none
ConfigurationManager.AppSettings["UserFullPermission"] is not working properly on web server and it directs me to AccessDenied.aspx even though my username is available in that key RRS feed

  • Question

  • I want to restrict access to my web application to a limited set of users. For this reason, I did the following:

    1) In web.config file, I added this code:

    <configuration>
      <appSettings>
        <add key="UsersFullPermission" value="myUserName" />

    </configuration>

    2) In Default.aspx, I added the below line before Page_Load event:

    string LoginUserName = HttpContext.Current.Request.LogonUserIdentity.Name.ToString().Split('\\')[1];

    3) Inside Page_Load event, I addded the below code:

    if (!IsPostBack)
                {
                    if (!ConfigurationManager.AppSettings["UsersFullPermission"].ToLower().Contains(LoginUserName.ToLower()))
                    {
                        HttpContext.Current.Response.Redirect("~/AccessDenied.aspx");
                    }
                }

    It seems everything is working fine when I build the solution in localhost. However, when I published my solution and accessed it from the web browser, it took me directly to AccessDenied.aspx. Any explanation why this behavior occurred? Is it something in my code or something in the web server that must change? Please advise.

    Friday, August 10, 2018 10:05 PM

All replies

  • ASP.NET Issues can be discussed at the ASP.NET forums.

    http://forums.asp.net/

    Saturday, August 11, 2018 9:11 PM
  • Hi Mohammed,

    The Visual C# forum discuss and ask questions about the C# programming language, IDE, libraries, samples, and tools. it will be more appropriate to ask your question at ASP.NET Forums.

    Thank you for your understanding.

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, August 13, 2018 1:44 AM