Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 页面不是';t正确重定向到站点维护页面_C#_Asp.net 4.0_Global Asax - Fatal编程技术网

C# 页面不是';t正确重定向到站点维护页面

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)

我想允许特定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,在此页面中,Understruction页面重定向正确完成,之后它进入循环,因为再次执行Global.asax beginrequest方法,最后我得到“页面未正确重定向”错误


请给我建议一个解决方案。

您真的要重写路径,还是打算使用
Response.Redirect()
?是否仅在请求的URL未以“PageUnderstruction.aspx”结尾时才执行重定向?是的。我也试过了。但是没有运气。