2
Reply

Cannot Navigate to Admin page or Show Admin Link !!

Terry

Terry

Mar 19 2015 10:06 AM
1.3k

Hi, 


    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 :
                        <LoggedInTemplate>
                            <ul class="nav navbar-nav">
                                <li><a runat="server" id="adminLink" visible="false" href="~/Admin/Admin_Page">Admin</a></li>
                                <li><a runat="server" href="~/Inquiries/Default.aspx">Inquiry</a></li>



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.




Answers (2)