C# 页面不是';t正确重定向到站点维护页面
我想允许特定IP地址的某些用户在web应用程序上工作,而其他用户只能看到维护页面下的站点 我的代码在Global.asax中编写如下C# 页面不是';t正确重定向到站点维护页面,c#,asp.net-4.0,global-asax,C#,Asp.net 4.0,Global Asax,我想允许特定IP地址的某些用户在web应用程序上工作,而其他用户只能看到维护页面下的站点 我的代码在Global.asax中编写如下 void Application_BeginRequest(object sender, EventArgs e) { //Site under Maintainance Code if (ConfigurationManager.AppSettings["MaintenanceMode"] != null)
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,在此页面中,Understruction页面重定向正确完成,之后它进入循环,因为再次执行Global.asax beginrequest方法,最后我得到“页面未正确重定向”错误
请给我建议一个解决方案。您真的要重写路径,还是打算使用
Response.Redirect()
?是否仅在请求的URL未以“PageUnderstruction.aspx”结尾时才执行重定向?是的。我也试过了。但是没有运气。