ins*_*um_ 36 c# ssl asp.net-web-api
我正在创建自托管Web API服务.为了保护它,我已经研究并实现了这篇文章,使用makecert成功生成了本地SSL证书并且我的服务已经过身份验证,如果我正在使用,则会生成令牌.
http://localhost/webapi/authentication/authenticate
Run Code Online (Sandbox Code Playgroud)
链接,但是当我尝试使用HTTPS访问我的服务时,我会在Firefox上关注:
SSL_ERROR_RX_RECORD_TOO_LONG
而对于同样的要求,Fiddler告诉我:
HTTP/1.1 502 Fiddler - 连接失败日期:2013年8月26日星期一10:44:27 GMT内容类型:text/html; charset = UTF-8连接:关闭时间戳:13:44:27.433
[Fiddler]与localhost的套接字连接失败.
无法与server.fiddler.network.https协商HTTPS连接>无法保护localhost的现有连接.由于意外的数据包格式,握手失败.
我的自主配置:
private HttpSelfHostServer _server;
private ExtendedHttpsSelfHostConfiguration _config;
public const string ServiceAddress = "https://localhost/webapi";
_config = new ExtendedHttpsSelfHostConfiguration(ServiceAddress);
_server = new HttpSelfHostServer(_config);
_server.OpenAsync();
Run Code Online (Sandbox Code Playgroud)
从这篇文章中获取的ExtendedHttpSelfHostConfiguration 是:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?提前致谢!
ins*_*um_ 35
根据我发现的这篇博文,我应该创建一个SSL证书并将其分配给特定端口(在我的情况下为99).
我已经创建了本地签名的SSL.然后得到它的Thumbprint和ApplicationId.使用CMD命令netsh(在Win7之前的系统中有一个httpcfg工具),我已经将我的证书分配给了端口
netsh http add sslcert ipport=0.0.0.0:99 certhash=3e49906c01a774c888231e5092077d3d855a6861 appid={2d6059b2-cccb-4a83-ae08-8ce209c2c5c1},其中certhash = SSL Thumbprint,appid = ApplicationId我之前已经复制过.
就是这样,现在我能够发出HTTPS请求了!
小智 5
将使用您指定的名称创建证书,找到它。
现在您已经创建了证书,是时候将其绑定到您在自助主机中使用的端口上了。如果是https:// localhost:5000
netsh http add sslcert ipport=0.0.0.0:5000 certhash=[cert-thumbprint] appid={[App-Id]}
[assembly: Guid("[app-id]")]
大功告成!
| 归档时间: |
|
| 查看次数: |
23868 次 |
| 最近记录: |