【发布时间】:2012-05-15 23:22:13
【问题描述】:
我在 IIS 7 中有以下规则:
<rule name="Category" enabled="true">
<match url="^store/([0-9]+)/(.*)" />
<action type="Rewrite" url="store?cid={R:1}" appendQueryString="false" logRewrittenUrl="true" />
</rule>
这似乎工作正常,但是在我的 ASP.Net MVC 3 应用程序中,我有几个 @Url.Content("~/") 条目解析为 /store/ 作为根而不是 /。例如,典型的 url 是 http://mysite.com/store/99/coats-with-hoods。
编辑/更新:我仍然在这个问题上大发雷霆,所以我决定研究 Url.Content 代码库,我注意到它会检查 URL 是否已被重写 (true) 以及是否所以它使路径相关,而 not 又给了我绝对 URL:
if (!PathHelpers._urlRewriterHelper.WasRequestRewritten(httpContext))
return contentPath;
string relativePath = PathHelpers.MakeRelative(httpContext.Request.Path, contentPath);
return PathHelpers.MakeAbsolute(httpContext.Request.RawUrl, relativePath);
有人知道为什么会这样吗?我有点困惑为什么会发生这种情况以及如何在我的应用程序中解释它?
【问题讨论】:
-
您能否提供更多关于您的项目和 IIS 在文件夹结构方面的设置的信息?
-
是在网站根目录下运行的,不是在虚拟目录下运行的,还有什么需要知道的?
标签: asp.net-mvc iis-7 url-rewrite-module umbraco5