我正在使用ASP.NET Core。关于Stackoverflow的问题/答案已经与使用自定义URL进行开发有关,但是我的处境似乎有所不同,因为我需要https支持和自定义基本URL。我正在通过OAuth重定向流程与第三方进行授权。第三方仅支持https而不是localhost的重定向URL。Visual Studio 2017(版本15.7.2)开箱即用,配置了https支持,这真是一个惊喜。默认情况下,我的应用在上启动https://localhost:44348/
。
launchSettings.json
看起来像这样:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53837",
"sslPort": 44348
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyProject.Web": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
我添加了一个主机条目以将自定义网址映射到127.0.0.1
127.0.0.1 app.mysite.local
...但是我无法通过访问我的网站https://app.mysite.local:44348/
。我得到一个Bad Request - Invalid Hostname
错误。
我尝试.vs/config/applicationhost.config
从以下方式更改此条目:
<binding protocol="https" bindingInformation="*:44348:localhost" />
至
<binding protocol="https" bindingInformation="*:44348:*" />
但是即使我以管理员身份运行Visual Studio,我的应用程序也根本无法运行。Visual Studio显示此对话框:
我什至尝试在上使用UseUrls()
扩展方法IWebHostBuilder
:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("https://*:44348/");
}
...但是这些技术似乎都不起作用。在开发ASP.NET Core应用程序时,谁能阐明如何在https上使用自定义基本URL的方法?
用更新的URL运行它,但是缺少证书,这可能是接下来要看的东西。当然,我知道这不是完整的答案,但是我认为最好提供一些帮助,因为我目前没有时间尝试通过证书问题。
尝试更改.vs/config/applicationhost.config
为以下内容(您需要将端口更新为您正在使用的端口),以便查看配置中的绑定通知,并在两个地方进行了更新:
<site name="WebSite1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8080:localhost" />
<binding protocol="https" bindingInformation="*:44335:app.mysite.local" />
</bindings>
</site>
<site name="WebApplication2" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\benl\source\repos\WebApplication2\WebApplication2" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:63297:localhost" />
<binding protocol="https" bindingInformation="*:44335:app.mysite.local" />
</bindings>
</site>
另外,我以管理员身份运行VS。我确实遇到了IIS错误,所以确实重新启动了。应用程序在localhost网址上加载,并抱怨请求错误。因此,现在输入您的URL https://app.mysite.local:44335 /(再次更改端口),它现在正在运行:
下一部分您将需要为IIS express排序一个新证书,因为它很可能仅是为localhost设置的。链接到可能的方法
这也可能有用链接到证书创建/用于localdev
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句