asp.net - Visual Studio无法在mvc3网站web.config中识别ssl和rewrite标签

标签 asp.net asp.net-mvc iis url-rewrite-module

我已经使用asp.net mvc3编写了一个简单的Web应用程序,并且我有一个登录页面来控制对该网站的访问。每个未经身份验证的请求都将重定向到此页面。

我想使用ssl来确保网站安全(使用https)。我不想在我所有的网站上都使用https,因为它使浏览器变得繁重。
问题是,当我在web.config中添加以下标记时,VS2010 Ultimate无法识别该标记并且无法正常工作。

我也已经将该项目部署到IIS 7.5,但是它也不起作用。我该怎么办?

  <system.webServer>
<rewrite>
  <rule name="Redirect to HTTP">
    <match url="secureDir/(.*)" negate="true" />
    <conditions>
      <add input="{HTTPS}" pattern="^ON$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" />
  </rule>

  <rule name="Redirect to HTTPS" stopProcessing="true">
    <match url="secureDir/(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
  </rule>
</rewrite>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>

最佳答案

您将需要IIS的URL Rewrite扩展,并且rewrite标签仅适用于IIS,因此您需要在项目中使用它。如果正确,则不一定需要VS来验证xml,但是如果需要,可以在这里找到指南:http://ruslany.net/2010/04/visual-studio-xml-intellisense-for-url-rewrite-2-0/

关于asp.net - Visual Studio无法在mvc3网站web.config中识别ssl和rewrite标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6943694/

相关文章:

c# - 如何生成新的 session ID

asp.net - 缺少 IUSR 帐户和 Asp.net 帐户

c# - Office Open XML SDK 电子表格如何在数字前显示货币符号?

asp.net-mvc - ASP.NET MVC 错误 : "Name ' __o' is not declared."

asp.net - 防止SQL注入(inject)攻击: the differences between mySql and SQL Server 2008

c# - ASP.NET Core .NET 6 Preview 7 Windows 服务

asp.net-mvc - 如何在Asp.net MVC中分离登录 View ?

c# - 在 ASP.NET/C#/IIS 站点上实现守护进程?

asp.net - 应用程序池回收如何影响ASP Net Session State?

asp.net-mvc - 如何在ReactJs中使用路由?