我希望允许来自特定IP地址的某些用户在Web应用程序上工作,而其他用户只会看到维护页面下的网站。
我的代码如下所示用Global.asax编写
void Application_BeginRequest(object sender, EventArgs e)
{
//Site under Maintainance Code
if (ConfigurationManager.AppSettings["MaintenanceMode"] != null)
{
if (Convert.ToBoolean(ConfigurationManager.AppSettings["MaintenanceMode"]))
{
if (ConfigurationManager.AppSettings["AllowedIPs"] != null)
{
string[] allowedIPs = ConfigurationManager.AppSettings["AllowedIPs"].ToString().Split(';');
if (!allowedIPs.Contains(GetIP()))
{
HttpContext.Current.RewritePath("~/Common/PageUnderConstruction.aspx", false);
}
}
}
}
}
private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length - 1].ToString();
}
初始页面是Login.aspx,在此PageUnderConstruction页面重定向正确完成后,随着Global.asax beginrequest方法再次执行,它进入循环,最后我得到“页面没有正确重定向”错误
请建议我一个解决方案。