启用Asp.Net WEB API 2自托管的Https

编程入门 行业动态 更新时间:2024-10-24 05:18:45
本文介绍了启用Asp.Net WEB API 2自托管的Https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

它的费用我两天了,使我的web服务支持HTTPS,有趣的是,我无法找到如何实现这一共同要求的任何正式文件。

It costs me 2 days already to make my web service support Https, the interesting thing is I could not find any official document on how to implement this common requirement.

参照一些帖子,这就是我所做的:

by referring some posts, this is what I did:

  • 从应用授权一个Http证书,并导入到Windows密钥库。

  • Applied a Http certificate from authority, and import to Windows key store.

现在我有2脚本命令,如:

Now I got 2 script commands like:

netsh的HTTP添加urlacl URL = 的http:// +:9999 / 用户=每个人

netsh http add urlacl url=+:9999/ user=Everyone

netsh的HTTP添加的sslcert ipport = 0.0.0.0:9999 CERTHASH = XXXXXXXXXXXXXXXXXXXX的appid = {12345678-db90-4b66-8b01-88f7af2e36bf}

netsh http add sslcert ipport=0.0.0.0:9999 certhash=XXXXXXXXXXXXXXXXXXXX appid={12345678-db90-4b66-8b01-88f7af2e36bf}

  • 修改code:

  • modify the code:

    string baseAddress = "+:9999/"; try { // Start OWIN host using (WebApp.Start<SelfHostStartup>(url: baseAddress)) { //.....

  • 运行该脚本2命令第一,看起来不错。运行我的应用程序,错误弹出:

  • Run that 2 script commands first, looks fine. Run my application, error pop up:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.HttpLi stenerException: Failed to listen on prefix '+:9999/' because it conflic ts with an existing registration on the machine. at System.Net.HttpListener.AddAllPrefixes() at System.Net.HttpListener.Start() at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener liste ner, Func`2 appFunc, IList`1 addresses, IDictionary`2 capabilities, Func`2 logge rFactory) at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app, IDic tionary`2 properties) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Objec t[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke Attr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuild er builder) at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(StartContext conte xt) at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context) at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions opt ions) at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options) at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider service s, StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start[TStartup](String url) at WayneCloud.Program.Main(String[] args)

  • 任何想法?

    [edit0]:通过使用的netstat -an ,我看不出端口 9999 在列表中。

    [edit0]: by using netstat -an, I could not see port 9999 on list.

    :通过使用 netsh的HTTP删除urlacl URL = HTTP:// +:9999 / ,异常不见了,现在 9999 是在的netstat -an 听,我尝试使用IE浏览器访问HTTPS URL,它给我一个 500 错误。

    [edit1]: by using netsh http delete urlacl url=+:9999/, the exception was gone, now the 9999 was on listening in netstat -an, I tried using IE to access a https url, it give me a 500 error.

    推荐答案

    您必须启用通过以下步骤HTTPS1.左键单击​​项目,进入属性查看 - >启用SSL设置为TRUE,并复制项目路径是一般的https://本地主机:44300 。然后右键单击应用程序的名称得属性 - >网络。变更项目URL和粘贴路径和保存。

    You have to enable https by following procedure 1. Left click on project, go to properties view-> Enable ssl set=true and copy the project path which is generally localhost:44300. Then right click on application name got to properties-> Web. Change project Url and paste that path and save.

更多推荐

启用Asp.Net WEB API 2自托管的Https

本文发布于:2023-11-15 04:14:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591056.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Net   Asp   WEB   Https   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!