locked
Issue with debugging (or deploying) Visual Studio on local IIS (using .core MVC) RRS feed

  • Question

  • User1270925057 posted

    Hello

    I have spent considerable time trying to do what I thought would be a simple task:  Debugging my website in Visual Studio on local IIS (using .core MVC) on my Windows 10 PC (instead of IIS Express) - or just being able to see it in localhost.

    I haven't really worked on the site yet - it is just the template site that is created in Visual Studio for .Core MVC.  When I debug with IIS Express it works fine.

    I am new to .core mvc but have previously worked with .net framework and .net forms.  Using this with localhost was easy.  I just had to setup my site in IIS.  I would then run localhost and the files I would see in Visual Studio (2013) would appear in the browser.

    I have tried to do the same with Visual Studio 2019 (a .core mvc site).  However when I run localhost I get 404 - page not found (HTTP Error 404. The requested resource is not found).  I have made sure that index.aspx and index.cshtml are included in default documents in IIS if this was required.

    I have been through several pages on the ASP.net docs website along with several other forums looking for a solution.   What I am unclear about is

    • In order to debug do I need to publish/deploy first (which I have also tried and doesn't change anything.  I set up a publish profile for localhost and still get 404). 
    • Is there a difference between debug, publish and deploy - are these all separate approaches (stages) to viewing my website in IIS?

    I have been through the following pages on Microsoft Docs:

    https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-enable-debugging-for-aspnet-applications?view=vs-2019#iis

    These steps included installing the  .NET Core Hosting Bundle which I have done.

    https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1

    Just to clarify using the debug options at the top of Visual Studio if I pick IIS express it works fine and the home page loads - if I select the debug profile for localhost that I setup I get the 404 page.  I don't get any errors on build.

    I would very much appreciate any advice.

    Thanks

    Friday, April 10, 2020 4:55 PM

Answers

  • User1270925057 posted

    Hello

    Thank you to all who took time to take a look at this.

    As can be the case, it is a simple problem that caused it - in that I didn't have my site binding setup correctly.

    Kind regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 14, 2020 11:08 AM

All replies

  • User415553908 posted

    One thing to check would be whether your VS is started as Administrator - when you open an IIS project, VS tries to set the application up for you, which might fail if you don't have enough rights. Which can in turn cause your debug to fail completely.

    Saturday, April 11, 2020 5:28 AM
  • User1270925057 posted

    Thank you for replying and your suggestion.  However, this isn't the problem as I have been using VS in administrator mode.

    Thanks anyway smile

    Saturday, April 11, 2020 10:50 AM
  • User409696431 posted

    Have you followed all the links in the ones you quoted?

    https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1 Host ASP.NET Core on Windows with IIS  (this doesn't happen out of the box - and it's not just installing the hosting bundle)

    https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-enable-debugging-for-aspnet-applications?view=vs-2019#iis  looking at the "Debug ASP.NET Core apps" section

    Saturday, April 11, 2020 7:27 PM
  • User1270925057 posted

    Hello

    Many thanks for your reply.   I have gone through all the steps again.  This is a summary:

    https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1

    • Host.CreateDefaultBuilder is installed (template does this)
    • There are config options for inprocess and outprocess but I don't believe these need to be changed for standard IIS hosting.  It doesn't say you have to.  I checked that my site is set to inprocess which is its and appears to be the preferred default (hosting model under process in the debug profile is set to inprocess)
    • Web.config file is in place (please see snippet 1 below).  I have set default pages but don't believe I need to.  Doesn't work either way.
    • I rechecked my IIS settings match which they do (these were already setup for previous sites (framework) I have worked on).
    • Both the .net sdk (3.1) and .net hosting 3.1.3 are installed (if I click either installer it says modify/repair rather than install).
    • I stopped and restarted the web service
    • The site is created with no managed code in IIS
    • I setup a publish profile in VS for IIS

    https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-enable-debugging-for-aspnet-applications?view=vs-2019#iis

    • I setup a debug profile for IIS (it is the only site running under IIS - so it should just use the localhost) e.g. App url 'http://localhost/.
    • Environment variables are set to ASPNETCORE_ENVIRONMENT - Development
    • Although it gives the options I don't believe I need to do any manual configuration.

    Snippet 1:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <location path="." inheritInChildApplications="false">
        <system.webServer>
          <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
          </handlers>
          <aspNetCore processPath="C:\_CurrentLT\Data\Websites\[mysitename]\bin\Debug\netcoreapp3.1\[mysitename].exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
            <environmentVariables>
              <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
              <environmentVariable name="ASPNETCORE_HTTPS_PORT" value="44366" />
              <environmentVariable name="COMPLUS_ForceENC" value="1" />
            </environmentVariables>
          </aspNetCore>
        </system.webServer>
      </location>
      <system.webServer>
        <directoryBrowse enabled="true" />
        <defaultDocument>
          <files>
            <add value="Index.cshtml" />
            <add value="Index.aspx" />
          </files>
        </defaultDocument>
      </system.webServer>
    </configuration>
    <!--ProjectGuid: 870992b0-9ff4-442b-b640-fad16e019099-->

    I also wanted to include a screenshot but I can't work out how to do this. Ctrl v does not work and the add image just seems to be for online images -  not to upload files.  Any help on this would also be appreciated.

    Any help or suggestions on the above will be much appreciated.

    Many thanks

    Monday, April 13, 2020 4:42 PM
  • User475983607 posted

    If I understand you want to connect the Visual Studio debugger to an application running on localhost (IIS).  I'm not sure if that's possible.  But, it's far more powerful to debug in Visual Studio because you get to see the debug information immediately in the output window or console depending on your setup.   I do dotnet run with the "watch" switch so every time I save a file it complies and runs the code.  

    Monday, April 13, 2020 5:53 PM
  • User1270925057 posted

    Hello

    Thank you to all who took time to take a look at this.

    As can be the case, it is a simple problem that caused it - in that I didn't have my site binding setup correctly.

    Kind regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 14, 2020 11:08 AM