在Global.asax文件中,当用于url重写时,Application_BeginRequest会干扰整个网站设计 [英] In Global.asax file Application_BeginRequest disturb whole website design when used for url Rewriting
本文介绍了在Global.asax文件中,当用于url重写时,Application_BeginRequest会干扰整个网站设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用Global.asax文件进行网址重写时,我使用Application_BeginRequest并跟进代码:
When I use Global.asax file for url rewriting purposes, I use Application_BeginRequest and follow up the code :
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 = "/abc/" + 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);
}
}
然而,当我在本地主机上运行时,该代码工作得非常好,但它让我的网站设计黯然失色他们的问题是iis有人可以帮助我吗?
However the Code is working fabulous but it dusturbs my website design when i run on local host, I think their is problem with iis can anyone help me?
推荐答案
根据MSDN的RewritePath发出新请求:
参见http://msdn.microsoft.com/en-us/library/system.web.httpcontext.rewritepath .aspx [ ^ ]
文本中的第一行:
将资源的请求重定向为与请求的URL指示的路径不同的路径。 RewritePath用于无cookie会话状态,以从URL中删除会话ID。
RewritePath according to MSDN makes a new request:
See http://msdn.microsoft.com/en-us/library/system.web.httpcontext.rewritepath.aspx[^]
First line in text:
Redirects a request for a resource to a different path than the one that is indicated by the requested URL. RewritePath is used in cookieless session state to strip session IDs from URLs.
这篇关于在Global.asax文件中,当用于url重写时,Application_BeginRequest会干扰整个网站设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文