【问题标题】:How to enable https in a MVC application [closed]如何在 MVC 应用程序中启用 https [关闭]
【发布时间】:2011-10-10 23:55:55
【问题描述】:

我很绝望。我尝试将我用 C# 开发的 MVC Rest 服务移动到 HTTPS 协议。我是普通的 java 程序员,我承认,我在 webapps 的整个配置方面遇到了一些严重的问题,特别是 web.config 文件,这对我来说是个大谜。

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

但是,一旦我这样做了,我就无法通过 http 或 https 访问网络服务。两者都给出了相同的错误:

提供的 URI 方案“https”无效;预期的“http”。 参数名称:context.ListenUriBaseAddress

谷歌搜索此错误表明我需要在我的 web.config 文件中配置传输安全性。我遇到的问题是,我的配置在某种程度上看起来与所有涉及激活 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>

任何提示如何解决这个问题都会受到欢迎。非常感谢

【问题讨论】:

标签: c# model-view-controller iis-7 https


【解决方案1】:

我发现了问题。 我正在使用来自 codeplex 的 WCF 库。如果还启用了 http,那么那里有一个错误会导致 https 失败。 我可以通过重做路由代码来规避这个问题。 遗憾的是我不能发布它,因为我不小心删除了我的整个 .net 项目:(

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-28
    • 2017-12-23
    • 2012-01-31
    • 2014-02-05
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多