我有一个带有布局页面等的标准 MVC3 项目。现在我需要制作漂亮的 URL。我开始玩 URL 重写模块。我正在尝试翻译http://localhost/Photographer/Pablo
成http://localhost/category-about.aspx?displayName=Pablo
,这是我的重写规则(非常简单!):
<system.webServer>
<rewrite>
<rules>
<rule name="about" patternSyntax="Wildcard">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="\.png|\.js|\.css|\.jpg" negate="true" />
</conditions>
<match url="photographer/*" />
<action type="Rewrite" url="category-about.aspx?displayName={R:1}" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
您在谷歌搜索尝试解决问题后添加的所有条件 - 但它们没有帮助。
我找到了这个页面:http ://www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms - 这表示〜运算符在重写时被服务器正确处理应用规则。但这显然不会在我的情况下发生 - 请参阅所附图片:
我的问题的解决方案是什么?我应该如何引用 CSS/JS 文件?我在 IIS 7.5 上使用 MVC3。
更新: 图像不是很清楚 - 但它表明我的 MasterLayout 页面有
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
但它被解决为
http://localhost/Photographer/Content/Site.css - and it gives 404
代替
http://localhost/Content/Site.css - which gives 200
当我请求此 URL 时:http://localhost/Photographer/Pablo
。逻辑工作正常 - 我的控制器获取请求并呈现页面 - 但它的 CSS 和图像丢失(因为它们前面有错误的根文件夹)。