User-595966692 posted
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.