我有一个带有布局页面等的标准 MVC3 项目。现在我需要制作漂亮的 URL。我开始使用 URL 重写模块。我正在尝试翻译http://localhost/Photographer/Pablo
into 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 http://www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms- 这表示应用重写规则时,服务器会正确处理 ~ 运算符。但在我的例子中显然不会发生这种情况 - 请参阅附图:
我的问题的解决方案是什么?我应该如何引用 CSS/JS 文件?我在 IIS 7.5 上使用 MVC3。
UPDATE:图像不是很清楚 - 但它显示我的 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 和图像丢失了(因为它们预先添加了错误的根文件夹)。