IIS 7重写规则和Url.Content问题 [英] IIS 7 rewrite rule and Url.Content issues

查看:689
本文介绍了IIS 7重写规则和Url.Content问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IIS 7以下规则:

I have the following rule in 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(〜/),其解析为/存储/为根,而不是/项。一个典型的网址是 http://mysite.com/store/99/coats-with-抽油烟机的例如

编辑/ UPDATE:我还在拉我的头发就这一个,所以我决定看看Url.Content code-基地,我注意到,它会检查URL已被重新写入(真)如果是这样它使相关的道路,这反过来做的不可以给我绝对网址:

EDIT/UPDATE: I'm still pulling my hair out on this one, so I decided to look into Url.Content code-base and I noticed that it checks if the URL has been re-written (true) and if so it makes the path relevant, which in turn does not give me the absolute URL:

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

人知道为什么会是什么?我有点困惑,为什么发生这种情况,我怎么能在我的应用程序占了?

Anyone know why this would be? I'm a bit confused as to why this is happening and how I can account for it in my application?

推荐答案

一次OK,我意识到,我是永远不会能够使用IIS重写对ASP.Net MVC我决定使用HttpContext.RewritePath相反,现在一切似乎是工作,因为它应该。

Ok once I realised that I was never going to be able to use IIS Rewrite against ASP.Net MVC I decided to use HttpContext.RewritePath instead, and now all appears to be working as it should.

这是一个相当基本的问题,因为它不只是Url.Content即受到影响,这是控制器的路线也一样,我有这个特定页面的形式,也被错误地指着店内/中/ /来代替。

This is quite a fundamental issue as it wasn't just Url.Content that was affected, it was controller routes too, I had a form on this particular page that was also incorrectly pointing to /store/ instead of /.

这篇关于IIS 7重写规则和Url.Content问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆