ASP.Net Context.RewritePath does not work when original URL contains query string

slove

New Member
I am writing IHttpModule to allow friendly URL access to our one of the detail page. When user is trying to access detail page using http://xyx.com/hotels/123/hotel-name.aspx page, re-write rule is going to applied in IHttpModule's OnBeginRequest method. Here, I wrote to change path to "~/DetailPages/DetailPage.aspx" using Context.RewritePath("~/DetailPages/DetailPage.aspx", "", "Code=123"), where 123 is code taken from Original URL.Now if original URL does not contain any query string, Detail page is getting invoked. But when user is trying to access http://xyz.com/hotels/123/hotel-name.aspx?show=advance then re-write code will be executed as \[code\]Context.RewritePath("~/DetailPages/DetailPage.aspx", "", "Code=123&show=advance")\[/code\]. Here we are getting an error saying "/hotels/123/hotel-name.aspx" page does not existing.Before & After Calling "\[code\]Context.RewritePath\[/code\]" method, I have taken details from \[code\]Context.Request\[/code\] object that is given below. Both looks perfect and same if there is no Query string in original URL. But when Original URL contains query string, Inside "Context_Error" (an event to listen any error for this request execution) method, when getting \[code\]Server.GetLastError()\[/code\] says "/hotels/123/hotel-name.aspx" page does not existing.Please refer below trace detail from \[code\]Context.Request\[/code\] object. Your help/inputs are welcome as i have spent 8 hrs already without any positive result.---------------------------Before - RewritePath Call---------------------------RawUrl : - /Hotels/123/hotel-name.aspx?a=bAppRelativeCurrentExecutionFilePath : - ~/Hotels/123/hotel-name.aspxCurrentExecutionFilePath : - /Hotels/123/hotel-name.aspxParams : - a=b&__utma=221736730.1213284380.1356606190.1356674469.1356687004.4.....(Windows+NT+5.1%3b+rv%3a7.0.1)+Gecko%2f20100101+Firefox%2f7.0.1Path : - /Hotels/123/hotel-name.aspxPhysicalPath : - D:\AppRoot\Hotels\161\hotel-name.aspxUrl : - http://xyz.com/Hotels/123/hotel-name.aspx?a=b---------------------------After - RewritePath Call---------------------------RawUrl : - /Hotels/123/hotel-name.aspx?a=bAppRelativeCurrentExecutionFilePath : - ~/DetailPages/DetailPage.aspxCurrentExecutionFilePath : - /DetailPages/DetailPage.aspxParams : - Code=123&a=b&__utma=221736730.1213284380.1356606190.1356674469.1356687004.4.....(Windows+NT+5.1%3b+rv%3a7.0.1)+Gecko%2f20100101+Firefox%2f7.0.1Path : - /DetailPages/DetailPage.aspxPhysicalPath : - D:\AppRoot\DetailPages\DetailPage.aspxUrl : - http://xyz.com/DetailPages/DetailPage.aspx?Code=123&a=b---\[code\]Server.GetLastError\[/code\] - Trace - Inside IHttpModule's Error Event--RawUrl : - /Hotels/123/hotel-name.aspx?a=bAppRelativeCurrentExecutionFilePath : - ~/Hotels/123/hotel-name.aspxCurrentExecutionFilePath : - /Hotels/123/hotel-name.aspxParams : - a=b&__utma=221736730.1213284380.1356606190.1356674469.1356687004.4....(Windows+NT+5.1%3b+rv%3a7.0.1)+Gecko%2f20100101+Firefox%2f7.0.1Path : - /Hotels/123/hotel-name.aspxPhysicalPath : - D:\AppRoot\Hotels\161\hotel-name.aspxUrl : - http://xyz.com/Hotels/123/hotel-name.aspx?a=bError Message The file '/Hotels/123/hotel-name.aspx' does not exist.Stack Trace \[code\]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)\[/code\]Can anyone find out what could be an issue?Thanks in advance.
 
Back
Top