ASP.NET Core application debugging without publishing on IIS

后端 未结 4 890
再見小時候
再見小時候 2020-12-30 11:49

I used to use asp.net mvc4 and in IIS my website\'s physical path would point my solution directory, and every time I update my code, I just re-build my solution and then I

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 12:29

    Follow these steps to be able to achieve what you want.

    1. In launchSettings.json, add a property named iis under iisSettings, like so:

      "iis": {
        "applicationUrl": "http://my.aspnetcoreapp.com"
      }
      
    2. Under the profiles section, add a new profile having commandName set to IIS. I am calling mine Local IIS. This will add a new option to the Run drop down named Local IIS.

      "Local IIS": {
        "commandName": "IIS",
        "launchBrowser": true,
        "launchUrl": "http://my.aspnetcoreapp.com",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      }
      
    3. Create a website in IIS. Set host name to my.aspnetcoreapp.com. Also create/use an app pool for this website that has .NET CLR version set to "No Managed Code".

    4. Set physical path of that website to the location of your asp.net core project, not the solution, unless of course if you have the project in the same folder as the solution.
    5. Add a loop back entry in the hosts file (for Windows C:\Windows\System32\drivers\etc\hosts)

      127.0.0.1 my.aspnetcoreapp.com

    6. Go back to Visual Studio, and run the application. Make sure you have "Local IIS" profile selected from Run drop-down. This will launch the application in the browser, at the URL, after a brief loading message that says "Provisioning IIS...".

    7. Done! From now on, you can launch your application at that URL, and can also debug by attaching to process w3wp.

    You could also host your app under "Default Web Site", by specifying the ULR like localhost/MyAspNetCoreApp instead of my.aspnetcoreapp.com. If you do that, a new app pool will be created with the name MyAspNetCoreApp AppPool.

    My medium article about this.

提交回复
热议问题