RickStrahl / AlbumViewerVNext

West Wind Album Viewer ASP.NET Core and Angular Sample
507 stars 353 forks source link

VS2017, F5 debugging error "web server request failed with status code 405, Method Not Allowed" #7

Closed mchubby closed 7 years ago

mchubby commented 7 years ago

Symptoms

Starting the project with debugging (F5) in Visual Studio 2017 yields the following error messagebox:

Unable to start process C:\Program Files\dotnet\dotnet.exe. The web server request failed with status code 405, Method Not Allowed. The full response has been written to (%temp%)\HttpFailure_03-04-40.html

The html report does not hold a lot of extended info, however %temp%\iisexpress\(random-number).log says:

Successfully registered URL "http://localhost:26448/" for site "AlbumViewerNetCore" application "/"
Registration completed for site "AlbumViewerNetCore"
Requête commencée : "DEBUG" http://localhost:26448/
Requête terminée : http://localhost:26448/wwwroot/index.html avec état HTTP 405.0

As you can see, a DEBUG verb is used to query the / URI.

Diagnosis

The web.config "blank" rule https://github.com/RickStrahl/AlbumViewerVNext/blob/2807706094163f69380f4caab91172d220046d95/src/AlbumViewerNetCore/web.config#L6 prevents debugging to start correctly.

Misc

Starting the project without debugging (Ctrl+F5) works normally.

mchubby commented 7 years ago

Quick fix

          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="DEBUG" ignoreCase="true" negate="true" />
          </conditions>

Do you want a PR?

RickStrahl commented 7 years ago

Interesting. I guess I haven't run with IIS Express in a long time :-(

Debugging works using Kestrel debugging directly, and the site works if the published app is mapped to full IIS, but as you found (nice sleuthing!) the problem is the DEBUG verb sent to the server as a special request to attach the debugger.

As suggested the fix is to fix the root web extensionless URL rewrite for the the DEBUG verb. The full section is:

<rule name="empty-root-index" stopProcessing="true">
    <match url="^$" />
    <action type="Rewrite" url="wwwroot/index.html" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="DEBUG" ignoreCase="true" negate="true" />
    </conditions>
</rule> 

Thanks and nice catch!