In my Asp.NET WEb forms App, I added Role Management and could successfully add and login as Admin and/or normal user.
To make the Admin link accessible, in my Site.Master, I have added the following :
By default, the adminLink is not visible. To make it visible on admin logged in, I added this code in CodeBehind of Site.Master
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.IsInRole("admin"))
{
//this.adminLink.Visible = true;
System.Diagnostics.Debug.WriteLine("$$$$$$$$$$ ADMIN LOGGED IN ");
try
{
Response.Redirect("/Admin/Admin_Page");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Error Navigating to Admin Page : " + ex.Message + "\n STACK : " + ex.StackTrace);
}
}
}
Here, nor adminLink is accessible not I am able to redirect to the Admin_Page.aspx. The error that I get on Redirecting is :
$$$$$$$$$$ ADMIN LOGGED IN
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll
Error Navigating to Admin Page : Thread was being aborted.
STACK : at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.AbortCurrentThread()
at System.Web.HttpResponse.End()
at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
at System.Web.HttpResponse.Redirect(String url)
at VincitoreCRMApplication.SiteMaster.Page_Load(Object sender, EventArgs e) in d:\pti\Vincitore\Projects\MyApplication\MyApplication\Site.Master.cs:line 78
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in MyApplication.dll
And the above lines just keep on coming. Can I know why is it behaving like this. I checked everything, all seems fine. Can't make out, why I am not able to access and navigate. Am I missing anything ??
FYI, I have used this site as reference - http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/membership-and-administration
Any help is highly appreciated.
TerryPosted Mar 19, 2015, 12:14 PM
But nothing worked among any thing in the stackoverflow options too. I removed the navigation part from Site.Master & in Login, using if condition navigates to the page using
IdentityHelper.RedirectToReturnUrl("~/Admin/Admin_Page", Response);
and this worked. This is solved.
But WHY I am not able to access id of
Bhushan GawalePosted Mar 19, 2015, 10:15 AM
Response.Redirect(url, false);
Context.ApplicationInstance.CompleteRequest();
Refer this link for more info -
http://stackoverflow.com/questions/2777105/why-response-redirect-causes-system-threading-threadabortexception