使用web.config中的位置标记进行IIS7和301永久重定向

Mik*_*ike 2 asp.net-mvc iis-7 web-config

我需要在IIS下运行的ASP.NET MVC应用程序的web.config中设置一些301永久重定向.

最简单的方法是在web.config文件中添加类似下面的标记:

 <location path="TheMenu.aspx">
        <system.webServer>
            <httpRedirect enabled="true" destination="menus/" httpResponseStatus="Permanent" />
        </system.webServer>
    </location>
Run Code Online (Sandbox Code Playgroud)

当我去网站时,http://domain.com/TheMenu.aspx它将我重定向到http://domain.com/menusxd而不是http://domain.com/menus.

会导致什么?

Cha*_*ino 6

抱歉,我帮不了你,<httpRedirect>但你试过/可以使用IIS7 URL Rewrite模块吗?

你的规则看起来像:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="TheMenu" patternSyntax="Wildcard" stopProcessing="true">
                <match url="TheMenu.aspx" />
                <action type="Redirect" url="menus/" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

HTHs,
查尔斯