gpt4 book ai didi

c# - 如何将我的 Azure 站点启用为 https 而不是 http?

转载 作者:可可西里 更新时间:2023-11-01 16:37:45 25 4
gpt4 key购买 nike

根据wisdom of the Internet ,如果我打算将我的网站托管为 something.azurewebsites.com(我就是这种情况),则安全架构已激活。

但是,当我调用下面的 (1) 时,我得到 404 - 找不到资源,而调用 (2) 会产生预期的行为。这些行之间的唯一区别是协议(protocol)的安全级别(复制粘贴两次!),因此我质疑所提供链接的真实性。

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

我该怎么办?!

但是,我也注意到:

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) { ... }
}
}

我的配置如下所示。第一个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>

最佳答案

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

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

其次是整个文件架构。

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

我已经尝试过这个配置(使用我的 WCF 服务名称和契约(Contract)),它在 http 和 https 上都运行良好。

关于c# - 如何将我的 Azure 站点启用为 https 而不是 http?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26952066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com