Asked by:
Url rewriting module doesn't work on classic pipline in IIS 7.5

Question
-
User1894845933 posted
Hi
I wrote a custom url rewriting http module that's work perfectly in Integrated managed pipline app pool.
but when I turn it to Classic, it stops working.
protected virtual void BaseModuleRewriter_AuthorizeRequest( object sender, EventArgs e) { HttpApplication app = (HttpApplication) sender; Rewrite(app.Request.Path, app); } protected void Rewrite(string requestedPath,HttpApplication app) { if (requestedPath.IndexOf('.') == -1) { Page page =PageManager.GetPageByAlias(requestedPath.EndsWith("/") ? requestedPath.Substring(0, requestedPath.Length - 1) : requestedPath); if (page != null) { app.Context.RewritePath(page.RelativeUrl == null ? "/Default.aspx?PageId=" + page.Serial : page.RelativeUrl.Substring(1), false); //app.Session["ThisPage"] = page; app.Response.StatusCode = 200; } else { app.Response.StatusCode = 404; } } }
I should explain that "Page" is a database entity that has "RelativeUrl" and "AliasAddress" property.
any Idea what's wrong?Tuesday, October 25, 2011 6:05 AM
All replies
-
User-2016190530 posted
Yup, when in integrated mode, you dont have to add the handler manually in IIS.
Go into IIS handlers tab, and add the handler there.
Modifiy your web config to hold the handler refference in the classic way under the handlers in system.web.
Under integrated, IIS moves the handler refferences in the Web config to new location under system.webserver
If you change all this you are good to go.
Tuesday, October 25, 2011 6:16 AM -
User1894845933 posted
Yup, when in integrated mode, you dont have to add the handler manually in IIS.
Go into IIS handlers tab, and add the handler there.
Modifiy your web config to hold the handler refference in the classic way under the handlers in system.web.
Under integrated, IIS moves the handler refferences in the Web config to new location under system.webserver
If you change all this you are good to go.
Thanks for your reply
This is a httpModule, so how can I add to to httpHandlers?
Tuesday, October 25, 2011 10:01 AM -
User-1598917946 posted
To use HttpModule you have to use Integrated pipeline mode ...
Tuesday, October 25, 2011 10:11 AM -
User1894845933 posted
To use HttpModule you have to use Integrated pipeline mode ...
OK
This is another problem. when I change the pipline to integrated it throws this exception:
"RegisterForEventValidation can only be called during Render();"
I set enableEventValidation to false (as many guys said) but it doesn't work.
This is very odd because I uploaded this application to another server and it works perfectly with integrated mode
Tuesday, October 25, 2011 10:19 AM -
User-1598917946 posted
Then it is more reason for you to check the settings in IIS on the new server ...
Tuesday, October 25, 2011 10:51 AM -
User1894845933 posted
Then it is more reason for you to check the settings in IIS on the new server ...
Any clue to where should I check?
Tuesday, October 25, 2011 10:54 AM -
User-1598917946 posted
Were both the servers on iis7.5?
Tuesday, October 25, 2011 11:07 AM -
User1894845933 posted
Were both the servers on iis7.5?
Yes, with same OS (Server 2008 R2)
Tuesday, October 25, 2011 11:09 AM