asp.net how to get back on previous page
I have developed a role based application and i have roles like Administrator, Operator..on every page I am checking if current user have assigned role then its allowed ..in my case i want to restrict "Operators" when they type in url of "Administrator.aspx" and get inside..in that case if user was on PAGE A and tries to hit the administrator url it should redirect back to PAge A ..Page A can be any other page names also....how to achieve this I am trying this way but its not working..
if (ViewState["URLReferrer"] == null)
ViewState["URLReferrer"] = Request.UrlReferrer;
开发者_开发百科 if (!HttpContext.Current.User.IsInRole("Control User"))
{
//If user is trying to access the admin page ..send back to the page where he is coming from.
Response.Redirect(Convert.ToString(ViewState["URLReferrer"]));
}
I've tried it. UrlReferer has Uri type, but you need string to use Response.Redirect
if (Request.UrlReferrer == null || string.IsNullOrEmtpy(Request.UrlReferrer.AbsoluteUri))
Response.Redirect("defaultPage")
else
Response.Redirect(Request.UrlReferrer.AbsoluteUri);
The above code works in my test web site. Try it.
精彩评论