如何在MVC应用程序中启用https

本文关键字:启用 https 应用程序 MVC | 更新日期: 2023-09-27 18:03:14

我绝望了。我尝试将我在c#中开发的MVC Rest服务转移到HTTPS协议。我通常是java程序员,我承认,我在webapps的整体配置上有一些严重的问题,尤其是web。配置文件,这对我来说是一个很大的谜团。

所以,我的问题。我有一个工作的Rest API在iis7上运行。从我的理解,我必须添加一个绑定到服务器的https。所以我创建了我的自定义证书,并添加了绑定。在IIS管理器中,现在有两个绑定,http和https。

但是,当我这样做时,我无法通过http或https访问web服务。两者都给出了相同的错误:

提供的URI方案'https'无效;预计"http"。参数名称:context。ListenUriBaseAddress

搜索此错误表明我需要在我的web中配置传输安全。配置文件。问题是,我的配置在某种程度上看起来与所有涉及https激活的示例完全不同。

<?xml version="1.0" encoding="utf-8"?>
<configuration> 
    <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <authentication mode="None"></authentication>
    <httpModules>
      <add name="CustomBasicAuthenticationModule" type="DMAlertRestServer.Server.Authentificator" />
    </httpModules>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>
  <connectionStrings>
    <add name="DBConnection"
     connectionString="
   Data Source=XXXXX;Initial Catalog=DBAlarmTest;Integrated Security=False;User ID=XXX;Password=XXX;"
     providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

任何提示如何解决这个问题将是非常受欢迎的。非常感谢

如何在MVC应用程序中启用https

我找到问题了。我正在使用来自codeplex的WCF库。有一个错误,让https失败,如果http也启用。我可以通过重新编写路由代码来解决这个问题。遗憾的是我不能发布它,因为我不小心删除了我的整个。net项目:(