如何启用我的Azure网站作为https而不是http?

时间:2014-11-15 23:38:18

标签: c# http azure ssl https

根据wisdom of the Internet,如果我打算以 something.azurewebsites.com (我的情况)托管我的网站,则安全模式已经激活。

但是,当我拨打下面的(1)时,我得到404 - 无法找到资源,而对(2)的调用会导致预期的行为。这些行之间的唯一区别是协议的安全级别(复制粘贴它,两次!)所以我质疑提供的链接的真实性。

  
      
  1. https://one-of-my.azurewebsites.net/SomeService.svc/Tester/beep
  2.   
  3. http://one-of-my.azurewebsites.net/SomeService.svc/Tester/beep
  4.   

我该怎么办?!

但是,我也注意到了:

  

https://one-of-my.azurewebsites.net/SomeService.svc

给了我通常的网站,这可能与方法定义本身的某些内容有关。它看起来有点像这样。

namespace One-of-my
{
  [ServiceContract(Namespace = "")]
  [AspNetCompatibilityRequirements(RequirementsMode 
    = AspNetCompatibilityRequirementsMode.Allowed)]
  public class SomeService
  {
    [OperationContract]
    [WebGet(
      UriTemplate = "Tester/{blopp}",
      ResponseFormat = WebMessageFormat.Json)]
    public async Task<String> Tester(String blopp) { ... }
  }
}

我的CONFIG如下所示。首先是 system.serviceModel

<system.serviceModel>
  <services>
    <service name="MySite.MyService">
      <endpoint address="" 
        behaviorConfiguration="MySite.MyServiceAspNetAjaxBehavior"
        binding="webHttpBinding" 
        contract="MySite.MyService" />
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="MySite.MyServiceAspNetAjaxBehavior">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata 
          httpGetEnabled="true" 
          httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
  </protocolMapping>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
    multipleSiteBindingsEnabled="true" />
</system.serviceModel>

在这里, system.webServer

<system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
      <add 
        name="Access-Control-Allow-Methods"
        value="GET,POST,DELETE,HEAD,PUT,OPTIONS" />
      <add 
        name="Access-Control-Allow-Headers" 
        value="X-Olaround-Debug-Mode, Authorization, Accept" />
      <add 
        name="Access-Control-Expose-Headers" 
        value="X-Olaround-Debug-Mode, X-Olaround-Request-Start-Timestamp, 
          X-Olaround-Request-End-Timestamp, X-Olaround-Request-Time, 
          X-Olaround-Request-Method, X-Olaround-Request-Result, 
          X-Olaround-Request-Endpoint" />
    </customHeaders>
  </httpProtocol>
  <modules runAllManagedModulesForAllRequests="true"/>
  <directoryBrowse enabled="true"/>
</system.webServer>

1 个答案:

答案 0 :(得分:1)

您必须使用<security mode="Transport" />添加绑定配置。 所以你的配置应该是这样的(首先是诀窍的部分)。

<bindings>
  <webHttpBinding>
    <binding name="HttpsConfiguration">
      <security mode="Transport" />
    </binding>
  </webHttpBinding>
</bindings>

遵循整个文件架构。

<system.serviceModel>
  <bindings> ... </bindings>
  <services> ... </services>
  <behaviors> ... </behaviors>
  ...
</system.serviceModel>

我已尝试过此配置(使用我的WCF服务名称和合同),它在http&amp; amp; HTTPS。