将非www重定向到www asp.net web.config

时间:2015-07-07 09:45:06

标签: c# asp.net web-config

我已尝试使用web.config文件中的代码片段将非www到www URL但我收到编译错误

<rewrite>
    <rules>
        <clear />
        <rule name="WWW Rewrite" enabled="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" negate="true"
                    pattern="^www\.([.a-zA-Z0-9]+)$" />
            </conditions>
            <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}"
                appendQueryString="true" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

编译错误:

  

无法在Web服务器上启动调试。请参阅常见帮助   配置错误。在调试器外部运行Web页面可能会   提供进一步的信息。

     

确保服务器运行正常。确认没有   通过在没有调试的情况下执行Debug.Start来完成web.config中的语法错误。   您可能还想参考ASP.NET和ATL Server调试   在线文档中的主题。

如何解决此问题?

1 个答案:

答案 0 :(得分:1)

您需要确保拥有URL Rewrite module installed,否则它将无效,您将收到与IIS无关的错误,无法理解您的web.config中的rewrite部分。