Question

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 Context.RewritePath("~/DetailPages/DetailPage.aspx", "", "Code=123&show=advance"). Here we are getting an error saying "/hotels/123/hotel-name.aspx" page does not existing.

Before & After Calling "Context.RewritePath" method, I have taken details from Context.Request 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 Server.GetLastError() says "/hotels/123/hotel-name.aspx" page does not existing.

Please refer below trace detail from Context.Request 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=b

AppRelativeCurrentExecutionFilePath : - ~/Hotels/123/hotel-name.aspx

CurrentExecutionFilePath : - /Hotels/123/hotel-name.aspx

Params : - a=b&__utma=221736730.1213284380.1356606190.1356674469.1356687004.4.....(Windows+NT+5.1%3b+rv%3a7.0.1)+Gecko%2f20100101+Firefox%2f7.0.1

Path : - /Hotels/123/hotel-name.aspx

PhysicalPath : - D:\AppRoot\Hotels\161\hotel-name.aspx

Url : - http://xyz.com/Hotels/123/hotel-name.aspx?a=b

--------------------------- After - RewritePath Call ---------------------------

RawUrl : - /Hotels/123/hotel-name.aspx?a=b

AppRelativeCurrentExecutionFilePath : - ~/DetailPages/DetailPage.aspx

CurrentExecutionFilePath : - /DetailPages/DetailPage.aspx

Params : - 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.1

Path : - /DetailPages/DetailPage.aspx

PhysicalPath : - D:\AppRoot\DetailPages\DetailPage.aspx

Url : - http://xyz.com/DetailPages/DetailPage.aspx?Code=123&a=b

---Server.GetLastError - Trace - Inside IHttpModule's Error Event--

RawUrl : - /Hotels/123/hotel-name.aspx?a=b

AppRelativeCurrentExecutionFilePath : - ~/Hotels/123/hotel-name.aspx

CurrentExecutionFilePath : - /Hotels/123/hotel-name.aspx

Params : - a=b&__utma=221736730.1213284380.1356606190.1356674469.1356687004.4....(Windows+NT+5.1%3b+rv%3a7.0.1)+Gecko%2f20100101+Firefox%2f7.0.1

Path : - /Hotels/123/hotel-name.aspx

PhysicalPath : - D:\AppRoot\Hotels\161\hotel-name.aspx

Url : - http://xyz.com/Hotels/123/hotel-name.aspx?a=b

Error Message The file '/Hotels/123/hotel-name.aspx' does not exist.

Stack Trace

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)

Can anyone find out what could be an issue?

Thanks in advance.

Was it helpful?

Solution

There was another IHttpModule changing URL when found Query String in Original URL. Hence I get what I need.

Thank you all for your kind suggestions and interest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top