我正在创建自托管 Web API 服务。为了确保它的安全,我研究并实施了this http://www.codeproject.com/Articles/630986/Cross-Platform-Authentication-With-ASP-NET-Web-API#_rating文章,使用 makecert 成功生成了本地 SSL 证书,并且我的服务已通过身份验证并生成令牌(如果我使用的话)
http://localhost/webapi/authentication/authenticate
链接,但是当我尝试使用 HTTPS 访问我的服务时,我在 Firefox 上收到以下信息:
ssl_error_rx_record_too_long
对于同样的请求,Fiddler 向我展示了:
HTTP/1.1 502 Fiddler - 连接失败日期:2013 年 8 月 26 日星期一
10:44:27 GMT 内容类型:text/html;字符集=UTF-8 连接:关闭
时间戳:13:44:27.433
[Fiddler] 与本地主机的套接字连接失败。
失败
与 server.fiddler.network.https> 协商 HTTPS 连接
无法保护本地主机的现有连接。握手
由于意外的数据包格式而失败。
我的自托管配置:
private HttpSelfHostServer _server;
private ExtendedHttpsSelfHostConfiguration _config;
public const string ServiceAddress = "https://localhost/webapi";
_config = new ExtendedHttpsSelfHostConfiguration(ServiceAddress);
_server = new HttpSelfHostServer(_config);
_server.OpenAsync();
扩展 HttpSelfHostConfiguration 取自何处这个帖子 https://pfelix.wordpress.com/2012/02/26/enabling-https-with-self-hosted-asp-net-web-api/ is:
public class ExtendedHttpSelfHostConfiguration : HttpSelfHostConfiguration
{
public ExtendedHttpSelfHostConfiguration(string baseAddress) : base(baseAddress) { }
public ExtendedHttpSelfHostConfiguration(Uri baseAddress) : base(baseAddress) { }
protected override BindingParameterCollection OnConfigureBinding(HttpBinding httpBinding)
{
if (BaseAddress.ToString().ToLower().Contains("https://"))
{
httpBinding.Security.Mode = HttpBindingSecurityMode.Transport;
}
return base.OnConfigureBinding(httpBinding);
}
}
我缺少什么?
提前致谢!
根据这篇博文 http://allen-conway-dotnet.blogspot.com/2012/02/applying-and-using-ssl-certificate-with.html我发现我应该创建一个 SSL 证书并将其分配给特定端口(在我的例子中为:99)。
我已经创建了本地签名的 SSL。然后就得到了指纹 and 应用程序ID。使用CMD命令netsh(在Win7之前的系统中有一个httpcfg工具),我已将我的证书分配给该端口
netsh http add sslcert ipport=0.0.0.0:99 certhash=3e49906c01a774c888231e5092077d3d855a6861 appid={2d6059b2-cccb-4a83-ae08-8ce209c2c5c1}
,其中 certhash = SSL指纹、appid =应用程序ID我之前已经复制过了
就是这样,现在我可以发出 HTTPS 请求了!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)