【发布时间】:2013-08-28 21:17:11
【问题描述】:
我正在创建自托管 Web API 服务。为了保护它,我研究并实施了this 文章,使用 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 内容类型:文本/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();
从this post 获取的 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);
}
}
我错过了什么? 提前致谢!
【问题讨论】:
-
您问题中帖子的链接看起来不正确:pfelix.wordpress.com/2012/02/26/…
-
对 https 进行更清晰的检查:BaseAddress.Scheme == "https"
标签: c# ssl asp.net-web-api