Global.asax文件中的Application_BeginRequest事件干扰了我在.net本地服务器上的网站 [英] Application_BeginRequest Event in Global.asax file disturbing my website at local server in .net

查看:56
本文介绍了Global.asax文件中的Application_BeginRequest事件干扰了我在.net本地服务器上的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Url重写代码时,它可以工作,但是它干扰了我在本地服务器上的站点,有人可以帮助我吗?我在.net中的global.asax文件中使用以下代码

When i use code of Url rewriting it works however it disturbs my site at local server can anybody help me out I am using the following code in global.asax file in .net

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        //Get the current http context
        HttpContext InRequest = HttpContext.Current;

        //Get the current path
        string OldPath = InRequest.Request.Path.ToLower();

        //Check the path whether it is a contextual path
        if (InRequest.Request.RawUrl.Split('/').Length > 3)
        {
            string Path = InRequest.Request.RawUrl.Split('/')[2];

            Path = "/" + Path + "/";

            string NewPath = "/furl/" + WebConfigurationManager.AppSettings[Path];

            string ItemName = InRequest.Request.RawUrl.Split('/')[InRequest.Request.RawUrl.Split('/').Length - 1].Split('.')[0];

            string ID = InRequest.Request.RawUrl.Split('/')[3];

            //Rewrite the path with the actual path
            InRequest.RewritePath(NewPath, "", "?id=" + ID, true);

        }
    }

推荐答案



您还没有提及您面临的问题.查看代码,我相信您必须绕过本地服务器的检查.如果您的本地服务器网址是这样的
Hi,

you haven''t mention what issue you are facing. Looking at the code I believe you have to bypass the checking in case of local server. If your local server url is like this
http://localhost:3325/mysite/


然后您可以看到


then you can see

if (InRequest.Request.RawUrl.Split('/').Length > 3)


将产生true并进行相应处理,因此您要么必须绕过对本地服务器的检查,要么必须处理这种情况.我希望这将有助于解决您的问题.


will yield true and process accordingly, so either you have to bypass the checking for local server or you have to handle this case. I hope this will help to solve your issue.


这篇关于Global.asax文件中的Application_BeginRequest事件干扰了我在.net本地服务器上的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆