简体   繁体   English

IIS7 HTTPModule无法重写MVC子应用程序的路径

[英]IIS7 HTTPModule not able to rewrite path to a MVC sub application

I have an HTTPModule running in IIS 7 providing a number of different URL rewrite services. 我在IIS 7中运行HTTPModule,提供了许多不同的URL重写服务。

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/ 我有一个子应用程序,它有自己的应用程序池,用MVC编写: http//www.SomeSiteWithURLrewrite.com/SubMVCApplication/

This module works great except for with MVC applications created as sub applications. 除了作为子应用程序创建的MVC应用程序之外,此模块工作得很好。

When I make an http request that will be rewritten: http://www.SomeSiteWithURLrewrite.com/Arbitrary/Path/To/Be/Rewritten 当我发出将被重写的http请求时: http : //www.SomeSiteWithURLrewrite.com/Arbitrary/Path/To/Be/Rewrite

I receive a HTTP Error 404.0 - Not Found 我收到HTTP错误404.0-未找到

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". 404错误页面显示已调用“http://www.SomeSiteWithURLrewrite.com/Arbitrary/Path/To/Be/Rewritten”并已重写为物理路径“C:{RootDirectory} \\ SubMVCApplication \\”与“ StaticFile”的处理程序。

I am not sure why the pipline is not recognizing the "HttpContext.Current.RewritePath" as an MVC request. 我不知道为什么pipline没有将“HttpContext.Current.RewritePath”识别为MVC请求。 Is it because the MVC app is in its own application? 是因为MVC应用程序在自己的应用程序中吗?

How can I call RewritePath (or something similar) and have IIS render an ASP.Net MVC page.in a sub application 如何在子应用程序中调用RewritePath(或类似的东西)并让IIS呈现ASP.Net MVC页面

If you cross the application boundaries you will need to do a Response.Redirect which issues a client based HTTP 301 redirect command 如果您跨越应用程序边界,则需要执行Response.Redirect,它会发出基于客户端的HTTP 301重定向命令

ReWritePath is a server only command, and needs access to the routing tables etc. Thus only the current application boundary ReWritePath是仅用于服务器的命令,需要访问路由表等。因此,仅当前应用程序边界

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 除了在每个Web应用程序中使页面代理通过内容进行传递外,没有简单的答案,但是这样做效率极低。

eg 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? 例如,将server.com/a/x重写为server.com/b/x,您的代码将必须检测应用程序边界更改,而在重定向时将发出HTTPRequest以获取server.com/b/x内容并将该内容传回客户端? Resource paths etc would become a big issue so probably not a good idea 资源路径等将成为一个大问题,所以可能不是一个好主意

I totally disagree with TFD's answer . 我完全不同意TFD的回答 Everything depends on algorithm that you want to implement. 一切都取决于您想要实现的算法。

Here you can find detailed description about routing and URL rewriting. 在这里,您可以找到有关路由和URL重写的详细说明。 As for me for the reason to implement tree base URL structure is better to use URL rewriting before routing, to 至于我为什么要实现树基URL结构,最好在路由之前使用URL重写

transform URL: my.site.com/page1/page2/page3/faq.aspx 转换网址: my.site.com/page1/page2/page3/faq.aspx
to: my.site.com/content/faq.aspx?parent=page3/page2/page1 至: my.site.com/content/faq.aspx?parent=page3/page2/page1

where content is the controller name and faq is a unique identifier. 其中content是控制器名称, faq是唯一标识符。

Data for that could be taken from database or sitemap file. 可以从数据库或站点地图文件中获取该数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM