asp.net-mvc - IIS 7 重写规则和 Url.Content 问题

标签 asp.net-mvc iis-7 url-rewrite-module umbraco5

我在 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) 以及是否所以它使路径相关,这反过来又给我绝对 URL:

    if (!PathHelpers._urlRewriterHelper.WasRequestRewritten(httpContext))
      return contentPath;
    string relativePath = PathHelpers.MakeRelative(httpContext.Request.Path, contentPath);
    return PathHelpers.MakeAbsolute(httpContext.Request.RawUrl, relativePath);

有人知道为什么会这样吗?我对为什么会发生这种情况以及如何在我的应用程序中解释它感到有点困惑?

最佳答案

好吧,一旦我意识到我永远无法对 ASP.Net MVC 使用 IIS 重写,我决定改用 HttpContext.RewritePath,现在一切似乎都在正常工作。

这是一个非常基本的问题,因为受影响的不仅仅是 Url.Content,它也是 Controller 路由,我在这个特定页面上有一个表单也错误地指向/store/而不是/。

关于asp.net-mvc - IIS 7 重写规则和 Url.Content 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10482299/

相关文章:

asp.net-mvc - 验证:模型或 View 模型

asp.net-mvc - ASP.NET MVC : How to POST complex object with Lists to server for Update (with/without FormCollection)

asp.net-mvc - ASP.Net MVC异常记录与错误处理结合

apache - 将 .htaccess 导入 IIS URL 重写 Web.Config 时出现问题

asp.net - IIS 重写不起作用(但重定向起作用)

asp.net-mvc - 响应中不存在 RequestVerificationToken cookie

asp.net - 如何使用 ASP.NET 查找 IIS 上 POST 的大小限制?

model-view-controller - 在 IIS7 上将 *.MVC 映射到 aspnet_isapi.dll

IIS URL 重定向更改查询字符串参数名称

asp.net - IIS - 打开基本身份验证会导致登录重定向循环