Iis ошибка 405

When issuing a perfectly cromulent verb to a local IIS Express web-site under Visual Studio 2013:

CROMULENT http://localhost:7579/Handler.ashx HTTP/1.1
Host: localhost:7579

the server responds with the error:

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE

That is a request to a «generic handler» (i.e. .ashx). If if i try again to a static resource:

SCHWIFTY http://localhost:7579/Default.htm HTTP/1.1
Host: localhost:7579

the server responds with the error:

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE

This is all by way to trying to use HTTP verbs:

DELETE http://localhost:7579/Handler.ashx HTTP/1.1
Host: localhost:7579

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE

PUThttp://localhost:7579/Handler.ashx HTTP/1.1
Host: localhost:7579

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE

This question has been asked to death, sometimes by me. But nobody has ever come up with a solution.

</Question>

Microsoft’s Bug

The problem, fundamentally, is that Microsoft ships IIS and IISExpress broken by default. Rather than handling HTTP verbs, as a web-server is required to do, they don’t handle verbs.

This can most easily be seen when managing full IIS running on Windows Server. Pick any of the built-in handlers (e.g. the cshtml handler), and you can see that someone thought it would be hilarious if it only worked with GET, HEAD, POST, and DEBUG verbs:

enter image description here

rather than correctly implementing support for HTTP in an HTTP server.

The question becomes:

  • why exactly doesn’t it work
  • how exactly to fix it
  • how to fix it in IIS Express (without any management tools)
  • why it continues to be shipped, year after year, broken

Question 1. Why doesn’t it work?

The first question is why doesn’t it work. Let’s look at an IIS server where we’ve removed every handler except the basic Static file handler:

enter image description here

The handler is configured to all all verbs:

enter image description here

The only handler left is set to allow any verb. Yet if we issue a request to the web server we get the error:

DELETE http://scratch.avatopia.com/ HTTP/1.1
Host: scratch.avatopia.com

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE
Server: Microsoft-IIS/7.5

Why is this happening?

Why didn’t it work? Where is the configuration option that says:

  • GET
  • HEAD
  • OPTIONS
  • TRACE

because the server itself is saying those are the only supported verbs.

Yet if we change it to a GET it works fine:

GET http://scratch.avatopia.com/ HTTP/1.1
User-Agent: Fiddler
Host: scratch.avatopia.com

HTTP/1.1 200 OK
Content-Type: text/html

Question 2. How to fix it?

The common wisdom is to remove WebDAV. Nobody knows what WebDAV is, how it could be a problem, why it is a problem, or why it exists if it only causes problems. WebDAV can be removed as a handler from the IIS administration user interface:

enter image description here

which is identical to adding a remove entry from the handlers section in web.config (the UI itself adds the entry to web.config for you):

<system.webServer>
    <handlers>
        <remove name="WebDAV" />
    </handlers>
</system.webServer>

Except this doesn’t work. So how do we fix it?

Starting with IIS it seems that WebDAV has become even more of a virus. Rather than simply disabling it as a handler, you have to completely install or remove it as a module:

<system.webServer>
  <modules>
    <remove name="WebDAVModule" />
  </modules>
  <handlers>
    <remove name="WebDAV" />
  </handlers>
</system.webServer>

That sounds like a reason idea, except in my test case, on IIS 7.5, WebDAV is both not installed, and removed as a module:

HTTP/1.1 405 Method Not Allowed
Allow: GET, HEAD, OPTIONS, TRACE
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Tue, 10 May 2016 19:19:42 GMT
Content-Length: 0

So, if we can figure out how to solve the problem, we can answer question number two.

Question 3. How to fix it in IIS Express

Starting with Visual Studio 20131, Visual Studio no longer uses a mini web-server called Cassini. It uses a portable install of IIS Express itself (i.e. IIS Express Windows feature doesn’t need to be installed).

Most of the above fix (attempts) (fail) in IIS. But nobody has dealt with them in IIS Express of Visual Studio 2013 (which is how this question is different from any others).

Question 4. Why does this keep happening?

It’s been over 15 years, and this still keeps happening. There must be a good reason why IIS does not function as a web-server. But what is it? I’ve not been able to find any knowledge base article, or blog post, explaining why the IIS team refuses to function correctly.

Bonus Reading

  • The most popular Stackoverflow question for this problem: ASP.NET Web API — PUT & DELETE Verbs Not Allowed — IIS 8

Research Effort

  • HTTP Error 405.0 — Method Not Allowed, with POST (no answer, php)
  • HTTP Error 405.0 — Method Not Allowed (no answer)
  • POST verb not allowed (php)
  • HTTP Error 405.0 — Method Not Allowed in ASP.net MVC5 (no answer, mvc)
  • JQuery File Uploader = error 405 IIS8.5 (jquery no answer)
  • IIS 7.5 405 Method Not Allowed for PUT from StaticFileModule (no answer, static module, iis)
  • The HTTP verb POST used to access path is not allowed («don’t use verbs»)
  • http error 405 method not allowed error with web.API (uninstall WebDAV; already isn’t)
  • Handling Perl IIS 7.5 (perl)
  • HTTP Error 405.0 — Method Not Allowed using Jquery ajax get (ajax)
  • What causes an HTTP 405 «invalid method (HTTP verb)» error when POSTing a form to PHP on IIS? (iis6, ftp, php)
  • http://forums.asp.net/t/1648594.aspx («have you tried pinging your computer»)
  • Angular $resource POST/PUT to WebAPI 405 Method Not Allowed (try removing WebDAV handlder and WebDAV module)
  • Http Error 405.0 — method not allowed iis 7.5 module staticfilemodule (no solution)
  • Unable to set up WebDAV with IIS 7 *(trying to setup webdav)*
  • Android SOAP request is returning HTTP Response 405 (no solution)
  • wcf service doesn’t allow POST (wcf)
  • WebAPI Delete not working — 405 Method Not Allowed (WebAPI; remove WebDAV)

The transition from the traditional ASP.NET to ASP.NET Core brought several improvements, but it also presented developers with a new set of challenges. Among these challenges, encountering a “405 Method Not Allowed” error when issuing PUT or DELETE requests to an ASP.NET Core application hosted on IIS can be particularly vexing. In this article, we’ll deep dive into understanding the reasons behind this error and how to resolve it.

Understanding the Error 405

Before diving into the specifics of the ASP.NET Core scenario, it’s crucial to understand what the “405 Method Not Allowed” error generally implies. The error is an HTTP response status code indicating that the web server has recognized the request method, but the target resource does not support it for the given URI.

Common Causes of Error 405 in ASP.NET Core on IIS

  • WebDAV Module: When hosting ASP.NET Core applications on IIS, the WebDAV module is frequently the culprit. This module is designed for authoring on the web and uses both the PUT and DELETE requests. If not configured correctly, it can interfere with applications that rely on these methods.
  • Missing or Incorrect Verb Handlers: IIS uses verb handlers to process requests. If these handlers aren’t correctly configured for PUT or DELETE, you’ll face a 405 error.

Solution

If your application does not require WebDAV, you can resolve many issues by simply disabling the WebDAV module. Add the following code to your web.config file:


<system.webServer>
    <modules runAllManagedModulesForAllRequests="false">
        <remove name="WebDAVModule"/>
    </modules>
    <handlers>
        <remove name="WebDAV" />
    </handlers>
</system.webServer>

Additional Tips

  • Enable Detailed Error Messages: To get a clearer picture of the root cause, ensure your IIS server is configured to show detailed error messages. This will provide more context and possibly point directly to the offending module or handler.
  • Logging: Incorporate logging within your ASP.NET Core application. Tools like Serilog or the built-in ILogger can capture detailed logs that can offer insights into any potential issues.
  • Check Route Configurations: Ensure that your ASP.NET Core routing configurations support the methods you’re trying to invoke.

Conclusion

The “405 Method Not Allowed” error in an ASP.NET Core application hosted on IIS can be a hurdle, but with a proper understanding of its roots and the right tools at your disposal, it’s a manageable one. Always remember that your application’s needs are unique; hence, always test thoroughly after making any changes to configurations or infrastructure.

  • Remove From My Forums
  • Question

  • User1840894103 posted

    I am creating a website that runs on Angular 10 as frontend and  enitity web API as backend. Many of my Angular pages push information to the next page via «POST». When submitting information from a Angular form using «POST» I receive the following
    error:

    HTTP Error 405.0 — Method Not Allowed

    The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.

    <fieldset>

    Most likely causes:

    • The request sent to the Web server used an HTTP verb that is not allowed by the module configured to handle the request.
    • A request was sent to the server that contained an invalid HTTP verb.
    • The request is for static content and contains an HTTP verb other than GET or HEAD.
    • A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.

    </fieldset>

    <fieldset>

    Things you can try:

    • Verify the list of verbs enabled for the module handler this request was sent to, and ensure that this verb should be allowed for the Web site.
    • Check the IIS log file to see which verb is not allowed for the request.
    • Check the failed request tracing logs for additional information about this error. For more information, click here.

    </fieldset>

    <fieldset>

    Detailed Error Information:

    Module    StaticFileModule
    Notification    ExecuteRequestHandler
    Handler    StaticFile
    Error Code    0x80070001
    Requested URL    http://localhost:62510/Register.html
    Physical Path    C:\Users\********\Documents\Visual Studio 2015\WebSites\Prismlib\Register.html
    Logon Method    Anonymous
    Logon User    Anonymous
    Request Tracing Directory    C:\Users\********\Documents\IISExpress\TraceLogFiles\PRISMLIB

    </fieldset>

    <fieldset>

    More Information:

    This error means that the request sent to the Web server contained an HTTP verb that is not allowed by the configured module handler for the request.

    </fieldset>

    I have tried changing the web.config file and adding/removing various handlers and modules , but it did not fix the issue.

    What do I need to do to resolve this error?

Symptoms

When attempting to POST to a web page in Internet Information
Services (IIS) 5.1 under Windows 2000 (Win2k) or Windows XP, you may
receive the following error:

The page cannot be displayed 
The page you are looking for cannot be displayed because the page address is incorrect.  

--------------------------------------------------------------------------------

Please try the following:

If you typed the page address in the Address bar, check that it is entered correctly.

Open the 127.0.0.1 home page and then look for links to the information you want. 
HTTP 405 - Resource not allowed
Internet Information Services

--------------------------------------------------------------------------------

Technical Information (for support personnel)

More information:
Microsoft Support  

The code in the sample page that was posted might have been:

<!-- test.html EXAMPLE -->
<html>
<head><title>Test Post</title>
</head>
<body>

<form method="post" action="test.html">
<input type="submit">
</form>

</body></html>

Cause

The file type is not registered in the IIS script map settings (e.g. .html or .htm). IIS 5.1 only
allows HTTP requests of type to GET to unmapped files. HTTP requests of type POST, HEAD, and all others are
responded to
with a 405 resource not allowed error.

As a security note, you should always remove unused script mappings. This is the default behavior of IIS 6, which will
only serve named extensions and refuse all others.

Resolution

Add a script map for the extension. A script map associates a particular file type
with a given script module. The web server runs the module on the given file and sends the output to the browser, instead of
sending the file directly to the browser.

  1. Go to «Control Panel»-«Administrative Tools»-«Internet Information Services».
  2. Expand the tree to «COMPUTERNAME«-«Web Sites»-«Default Web Site».
  3. Right-click on «Default Web Site» and select «Properties». (Alternately, select «Default Web
    Site» and press Alt+Enter.)
  4. Select the «Home Directory» tab.
  5. Click the «Configuration» button.
  6. From the «Mappings» tab, select the «Add» button.
  7. Click the «Browse…» button, choose «Dynamic Link Libraries
    *.dll» from the «Files of Type» dropdown, and select c:\WINDOWS\System32\inetsrv\asp.dll.
  8. Type «.html» (without quotes) in the «Extension» box.
  9. Select the «Limit to:» radio button, and type in «GET, POST» (without quotes)
    in the box next to it.
  10. Click the «OK» button and close all the dialogs. (If the «OK» button is greyed out, then make sure
    all the entries are correct and try clicking in the file name box.)

See the screen shot below. You must adjust the above instructions to your particular OS, web site configuration, and file
type. You can associate the file type with a
different script engine besides asp.dll, which is the ASP 3.0 script engine. There is no need to give
IWAM_COMPUTERNAME permission to the file, only IUSR_COMPUTERNAME needs NTFS
read and execute permission.

Screen Shot

Screen shot of IIS Script Mappings Configuration Panel

More Information

Applies to

Internet Information Services (IIS) 5.1

Windows XP

Windows 2000

Links

  • Microsoft Knowledge Base Article — 238461 — Error Message: 405 Method
    Not Allowed when using FrontPage 2000 Server Extensions from Microsoft or Microsoft Office 2000 Server Extensions
  • Troubleshooting
    Common IIS Errors
  • Microsoft Advanced Search — Search for «HTTP 405 — Resource not allowed»

Created 2004-12-16,
Last Modified 2011-07-24,
© Shailesh N. Humbad


Disclaimer: This content is provided as-is.
The information may be incorrect.

Recently , I was delivering a project for a client , and usually what I do is , I prepare CI/CD pipelines , I test the project and I deliver it .

That worked fine , but this time , the client wants the project to be hosted on his own virtual machine , no problem with that let me do it ,it will take 15 min and  later I can go  jogging or maybe watch an episode of Gotham and see what will happen to Bruce! .

I published the project to a folder , launched IIS ,added a new site and hosted it ,good , let  me test !

I tested the create and get methods ,they worked , and the lesson that I learned in my earlier job is that I need to test everything ,not just 1 or 2 methods but everything !

And boom ! the delete and put methods don’t work ! what’s going on !

I mean they work in Visual studio ?! they work in app service  on azure !

What’s going on and what the heck is this !

” IIS 10.0 Detailed Error – 405.0 – Method Not Allowed ”

it’s Friday 5 PM and this happens .. “the difference between the past and the present  that , I used to freak out but now I smile and say : Oh yeah , something new to learn and share !”

So , I said to my self : right now I have 3 goals :

1- Fix this no matter what, so it’s works and the client can start testing

2- know why this happened and fix it if it needs to be fixed again.

3-share this .

So ,I started the search and if you are looking to quick fix all you have to do now is to insert those lines to web.config under system.webServer

<modules runAllManagedModulesForAllRequests="false"> 
        <remove name="WebDAVModule" /> 
        </modules>

PS : You may need to recycle the app pool or restart IIS for this change to take effect.

Now it’s time to understand why this happened ,the first tought that came to my mind is WebDav can cause IIS to block the Delete and the Put calls ,and if there is no WebDav there is no problem and no block .

What is WebDAV?

WebDAV is short for Web Distributed Authoring and Versioning, and it is an open-standard extension to the HTTP protocol that enables file management over the Internet. In addition to the usual file system-like operations (copy, move, delete, etc), WebDAV adds a flexible property mechanism (based on name/value pairs) and resource locking. WebDAV is a critical component in Microsoft’s web publishing story, used by the WebDAV redirector, Web Folders, SMS/SCCM, and many other components.

Anonymous PROPFINDs are allowed for file listings, but file uploads and WebDAV-based GET requests require an authenticated user. This is a change from IIS 6.0, where anonymous WebDAV file uploads/downloads could be enabled by opening up your security. In WebDAV for IIS 7.0 and above we changed this behavior so that all WebDAV activity would require authentication, but we allow for the use of anonymous PROPFINDs for backward-compatibility with some WebDAV clients. (More specifically, the PUT, MKCOL, PROPPATCH, COPY, MOVE, DELETE, and WebDAV-based GET requests all require authentication.)

If you need more informations you can read from :  link

The Fix  

After understanding what is WebDav now it’s time to see the fix and how can be done .

1-Deleting WebDAV :

If there is no need for you to use WebDav in general , you can remove it from the system , if you are using windows 10 you can go to “Turn Windows Features On or Off” and uncheck it

In Windows Server you need to go to removing features in server manager .

2- A Quick Fix :

The fix can be done by adding to the web.config:

<modules runAllManagedModulesForAllRequests="false"> 
        <remove name="WebDAVModule" /> 
        </modules>

hope this was helpful 🙂

Понравилась статья? Поделить с друзьями:
  • Illegal use of floating point c ошибка
  • Importrange ошибка загрузка данных
  • Igkmd64 sys ошибка
  • Illegal string offset php ошибка
  • Importrange google таблицы внутренняя ошибка при импорте диапазона