如何在Visual Studio 2015中设置ASP.NET Core Web Application的URL

Pau*_* Ma 9 iis-express asp.net-core-mvc visual-studio-2015 asp.net-core

我在Visual Studio 2015中创建了一个名为"HelloASPNETCore"的ASP.NET核心Web应用程序,默认模板有一个控制器"Home"和几个动作"Index","Contact"..... etc; 现在我想在IIS Express上以root URL启动它

http://localhost:29492/HelloASPNETCore
Run Code Online (Sandbox Code Playgroud)

但Visual Studio为我设置的默认URL是

http://localhost:29492
Run Code Online (Sandbox Code Playgroud)

在经典的ASP.NET MVC Web应用程序项目中,我刚刚在项目属性中指定了项目URL,但它可以工作,但它在ASP.NET核心Web应用程序项目中不起作用.我在浏览器上输入了URL http:// localhost:29492/Home/Index并得到了正确的内容响应,但是http:// localhost:29492/HelloASPNETCore/Home/Index给了我空的内容,没有任何错误信息.

Adr*_*ris 13

属性文件夹中,您有文件launchSettings.json,您可以在其中设置应用程序的某些设置.

你会发现这样的事情:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:52023/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "index",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "YOUR_PROJECT_NAMESPACE": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "http://localhost:52023/index",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)


Ash*_*put 6

您可以在编写服务器相关内容的地方定义它

var host = new WebHostBuilder()
    .UseKestrel()
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseUrls("http://localhost:29492/HelloASPNETCore")
    .UseIISIntegration()
    .UseStartup<Startup>()
    .Build();
Run Code Online (Sandbox Code Playgroud)

如果您使用的是Visual Studio,则可以通过properties/launchSettings.json使用如下所示的正确修改文件来实现launchUrl

"launchUrl": "http://localhost:29492/HelloASPNETCore"
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请关注本文

您必须设置要支持的路由。