开发者

IIS7 HTTPModule not able to rewrite path to a MVC sub application

开发者 https://www.devze.com 2023-01-26 14:00 出处:网络
I have an HTTPModule running in IIS 7 providing a number of different URL rewrite services. For example:

I have an HTTPModule running in IIS 7 providing a number of different URL rewrite services.

For example:

public void Init(HttpApplication context)
{
    ...
    HttpContext.Current.RewritePath(landingPage.NewPath,
                                string.Empty,
                                landingPage.NewQueryString +
                                ((landingPage.NewQueryString == string.Empty) ? "" : "&") +
                                queryString);
    ...
}

开发者_运维技巧I have a sub application with its own app pool written in MVC: http://www.SomeSiteWithURLrewrite.com/SubMVCApplication/

This module works great except for with MVC applications created as sub applications.

When I make an http request that will be rewritten: http://www.SomeSiteWithURLrewrite.com/Arbitrary/Path/To/Be/Rewritten

I receive a HTTP Error 404.0 - Not Found

The 404 error page shows that there was a call to "http://www.SomeSiteWithURLrewrite.com/Arbitrary/Path/To/Be/Rewritten" that had been rewritten to the physical path "C:{RootDirectory}\SubMVCApplication\" with the handler of "StaticFile".

I am not sure why the pipline is not recognizing the "HttpContext.Current.RewritePath" as an MVC request. Is it because the MVC app is in its own application?

How can I call RewritePath (or something similar) and have IIS render an ASP.Net MVC page.in a sub application


If you cross the application boundaries you will need to do a Response.Redirect which issues a client based HTTP 301 redirect command

ReWritePath is a server only command, and needs access to the routing tables etc. Thus only the current application boundary

There is no easy answer, other than making a page proxy in each web application to pass through content, but this would be highly inefficient

e.g. server.com/a/x rewritten to server.com/b/x, you code would have to detect the application boundary changem, and would instead on a redirect would issue an HTTPRequest to get the server.com/b/x content and pass that content back to client? Resource paths etc would become a big issue so probably not a good idea


I totally disagree with TFD's answer. Everything depends on algorithm that you want to implement.

Here you can find detailed description about routing and URL rewriting. As for me for the reason to implement tree base URL structure is better to use URL rewriting before routing, to

transform URL: my.site.com/page1/page2/page3/faq.aspx
to: my.site.com/content/faq.aspx?parent=page3/page2/page1

where content is the controller name and faq is a unique identifier.

Data for that could be taken from database or sitemap file.

0

精彩评论

暂无评论...
验证码 换一张
取 消