我想将已定义的Controller和Action添加到基本URL
localhost:6473 -> localhost:6473/Beta/Index
在Web.config中重写URL但由于某种原因它无法正常工作
<rewrite>
<rules>
<rule name="Beta_Local" stopProcessing="true">
<match url="(localhost*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern= "^localhost:[0-9]{4}$" negate="true"/>
</conditions>
<action type="Redirect" url="{R:0}/Beta/Index" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
答案 0 :(得分:2)
匹配网址不应包含域名,而应包含路径。如果你想捕获root /你需要
<match url="^$" />
请参阅http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference
此外,您似乎不需要localhost的附加条件。
完整规则可以遵循
<rewrite>
<rules>
<rule name="Beta_Local" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/Beta/Index" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
P.S。
如果您需要以MVC方式进行,可以使用路由
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Beta", action = "Index", id = UrlParameter.Optional }
);