Visual studio ASP.NET核心:使用自定义基本URL和https在本地开发

Visual studio ASP.NET核心:使用自定义基本URL和https在本地开发,visual-studio,asp.net-core,Visual Studio,Asp.net Core,我正在使用ASP.NET内核。关于Stackoverflow,已经有一些与使用自定义URL开发相关的问题/答案,但我的情况似乎有点不同,因为我需要https支持和自定义基本URL。我正在授权第三方使用OAuth重定向流。第三方仅支持https但不支持localhost的重定向URL。Visual Studio 2017(版本15.7.2)立即配置了https支持,这是一个惊喜。默认情况下,我的应用程序在https://localhost:44348/ launchSettings.json如下所

我正在使用ASP.NET内核。关于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"
      }
    }
  }
}
我添加了一个主机条目,将自定义url映射到127.0.0.1

127.0.0.1       app.mysite.local
…但我无法访问位于
https://app.mysite.local:44348/
。我收到一个
错误请求-无效主机名
错误

我已尝试在
.vs/config/applicationhost.config
中从以下位置更改此条目:

<binding protocol="https" bindingInformation="*:44348:localhost" />

……但这些技术似乎都不管用。在开发ASP.NET核心应用程序时,有谁能解释一下如何让自定义基本URL在https上工作吗?

已经使用更新的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>

(再次更改端口)它现在正在运行:

下一部分,您将需要为IIS express排序一个新证书,因为它很可能只为localhost设置


这也可能有用

你能从你的启动设置中提供更多信息吗,我猜你那里也有个人资料。我猜这不应该是个问题,但是为什么在applicationUrl中不使用app.mysite.local而不是localhost呢?在更新主机文件后是否重新启动了。我记得这是一个潜在的问题。@eVolve我用完整的
launchSettings.json
更新了我的帖子。是的,那里有个人资料。我尝试将applicationUrl更改为app.mysite.local,但得到了与上面屏幕截图相同的
无效URI:无法解析主机名
错误消息。我不认为是主机文件没有更新,因为URL似乎正确地路由到应用程序。太棒了,它可以工作了!看起来你在
WebSite1
中添加了
app.mysite.local
绑定,但我认为没有必要。似乎只需要
WebApplication2
中的一个。如果除了新的https app.mysite.local绑定之外,您还保留了旧的https localhost绑定,那么您将能够在这两个
https://localhost:44335
https://app.mysite.local:44335
。遗憾的是,当您添加
app.mysite.local
绑定时,您需要以管理员身份运行Visual Studio,否则IIS将无法启动。
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/");
}
      <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>