ASP.NET 5 MVC: unable to connect to web server 'IIS Express'

后端 未结 30 1752
北恋
北恋 2020-12-12 13:28

What I\'m doing:

  • Opening Visual Studio Community 2015
  • File -> New -> Project
  • Under Visual C#: Web -> ASP.NET Web Application
  • Web App
相关标签:
30条回答
  • 2020-12-12 13:54

    I won't pretend to fully understand what MS bug creates this problem, but here is another potential solution:

    In the .vs/config/applicationHost.config file, find the section for <system.applicationHost><applicationPools>. Under the pools, ensure that the managedRuntimeVersion attribute value matches the value which is in the IIS config for the system (and/or the version of the .NET framework which is installed).

    For example, you may find (as I did) that the generated file has:

        <add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
    

    In my case, you would replace this with:

        <add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0.30319" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
    

    Note the replacement from "v4.0" to "v4.0.30319". This resolved the issue.


    What appears to be going on:

    I believe that VS is generating an applicationHost.config file with "default" versions for the .NET framework, which may not match the specific version which is installed/configured on the system. You can debug/observe this issue by tracing the execution in Process Monitor, and finding the command line for iisexpress.exe. Running this command with /trace:error added yields a more informative message about a failure to preload the CLR with version v4.0. To wit:

    Starting IIS Express ...
    Failed while trying to preload CLR version v4.0. hr = 80131700
    Failed to initalize the W3WP_HOST hr = 80131700
    Process Model Shutdown called
    Unable to start iisexpress.


    Anyway, figured this might be helpful to someone else, since it's common enough to have multiple references online with bad information, and I've personally hit it a few times now.

    0 讨论(0)
  • 2020-12-12 13:54

    My solution (for .net core 2.0) was that i had forgot to add the port number in the applicationUrl, under iisExpress in launchSettings.json

    "iisExpress": {
      "applicationUrl": "https://localhost:50770",
      "sslPort": 50770
    }
    
    0 讨论(0)
  • 2020-12-12 13:55

    Try using a different port. I just set up a new Core 1.0 RC1 project and got the same error.

    • Right click web project
    • Debug tab
    • Toggle Enable SSL off and on again, it should generate a new random port
    • Copy the SSL URL and paste into Launch URL box
    • Run the project

    Worked for me (TM).

    Answer from: https://stackoverflow.com/a/28650554/134761

    0 讨论(0)
  • 2020-12-12 13:55

    TO CLARIFY

    Really a lot of answers here are the same and say something like "Restart and it magically works again".

    Well, 9 out of 10 times people have this issue like the OP it is because THE IP-ADDRESS IS ALREADY IN USE.

    ANSWER

    There could be 2 ip-addresses that are in use. Both of them you can find by:

    1) Right-clicking on the start-up project

    2) Click on "Properties"

    3) Click on the "Debug" tab

    Here you see your "App URL" and your "SSL URL".

    • If your "App URL" is in use, just change it there and save it and it should work again.

    • If your "SSL URL" is in use, close down VS, delete the "applicationhost.config" file in the hidden .vs folder of your project and open VS up again.

    0 讨论(0)
  • 2020-12-12 13:56

    In my case that was some other application listening on the same port which IIS Express trying to attach to. I have to run netstat -ao to see PID of process which is use same port and shutdown application. In my case application was Viber.

    0 讨论(0)
  • 2020-12-12 13:57

    Just close the visual studio and reopen and execute. It worked for me.

    0 讨论(0)
提交回复
热议问题