当原始URL包含查询字符串时,ASP.Net Context.RewritePath不起作用
我正在编写IHttpModule,以允许友好的URL访问我们的其中一个详细信息页面。当用户试图使用page访问详细页面时,重写规则将应用于IHttpModule的OnBeginRequest方法中 在这里,我编写了使用Context.RewritePath(“~/DetailPages/DetailPages.aspx”,“Code=123”)将路径更改为“~/DetailPages/DetailPages.aspx”,其中123是从原始URL获取的代码 现在,若原始URL不包含任何查询字符串,那个么将调用详细信息页面。但当用户试图访问时,重写代码将作为当原始URL包含查询字符串时,ASP.Net Context.RewritePath不起作用,asp.net,rewritepath,Asp.net,Rewritepath,我正在编写IHttpModule,以允许友好的URL访问我们的其中一个详细信息页面。当用户试图使用page访问详细页面时,重写规则将应用于IHttpModule的OnBeginRequest方法中 在这里,我编写了使用Context.RewritePath(“~/DetailPages/DetailPages.aspx”,“Code=123”)将路径更改为“~/DetailPages/DetailPages.aspx”,其中123是从原始URL获取的代码 现在,若原始URL不包含任何查询字符串,
Context.RewritePath(“~/DetailPages/DetailPage.aspx”,“code=123&show=advance”)
执行。在这里,我们得到一个错误,即“/hotels/123/hotel name.aspx”页面不存在
在调用“Context.RewritePath
”方法之前和之后,我从下面给出的Context.Request
对象中获取了详细信息。若在原始URL中并没有查询字符串,那个么这两者看起来都是完美的、相同的。但是,当原始URL包含查询字符串时,在获取Server.GetLastError()
时,在“Context\u Error”(侦听此请求执行的任何错误的事件)方法中,“/hotels/123/hotel name.aspx”页面不存在
请参考以下上下文中的跟踪详细信息。请求对象。欢迎您的帮助/投入,因为我已经花了8个小时没有任何积极的结果
---------------------------
前重写路径调用
---------------------------
RawUrl:-/Hotels/123/hotel name.aspx?a=b
AppRelativeCurrentExecutionFilePath:-~/Hotels/123/hotel-name.aspx
CurrentExecutionFilePath:-/Hotels/123/hotel-name.aspx
参数:-a=b&uu-utma=221736730.1213284380.1356606190.1356674469.1356687004.4…(Windows+NT+5.1%3b+rv%3a7.0.1)+壁虎%2F200101+Firefox%2f7.0.1)
路径:-/Hotels/123/hotel-name.aspx
物理路径:-D:\approt\Hotels\161\hotel-name.aspx
网址:-
---------------------------
重写后路径调用
---------------------------
RawUrl:-/Hotels/123/hotel name.aspx?a=b
AppRelativeCurrentExecutionFilePath:-~/DetailPages/DetailPages.aspx
CurrentExecutionFilePath:-/DetailPages/DetailPages.aspx
参数:-Code=123&a=b&uu-utma=221736730.1213284380.1356606190.1356674469.1356687004.4…(Windows+NT+5.1%3b+rv%3a7.0.1)+Gecko%2F200101+Firefox%2f7.0.1)
路径:-/DetailPages/DetailPages.aspx
物理路径:-D:\AppRoot\DetailPages\DetailPages.aspx
网址:-
--Server.GetLastError
-跟踪-在IHTTP模块的错误事件中--
RawUrl:-/Hotels/123/hotel name.aspx?a=b
AppRelativeCurrentExecutionFilePath:-~/Hotels/123/hotel-name.aspx
CurrentExecutionFilePath:-/Hotels/123/hotel-name.aspx
参数:-a=b&u-utma=221736730.1213284380.1356606190.1356674469.1356687004.4…(Windows+NT+5.1%3b+rv%3a7.0.1)+壁虎%2F200101+Firefox%2f7.0.1)
路径:-/Hotels/123/hotel-name.aspx
物理路径:-D:\approt\Hotels\161\hotel-name.aspx
网址:-
错误消息
文件“/Hotels/123/hotel name.aspx”不存在
堆栈跟踪
at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
有人能找出什么是问题吗
提前感谢。在原始URL中找到查询字符串时,另一个IHTTP模块正在更改URL。因此我得到了我所需要的
感谢大家的建议和兴趣。为什么不使用Microsoft提供的“重写”模块?这在IIS上吗?如果是,是什么版本?这是在IIS 5.5(Win XP)上,并将部署在IIS7上。我在这里关心的是,为什么它在原始URL包含查询字符串时不工作,而在没有查询字符串时工作。如果我解决了这个问题,我就完成了我所需要的。但我会检查内置的IIS重写模块。谢谢你的建议。