jQuery POST,错误 405 方法不允许 [英] jQuery POST, Error 405 Method not allowed

查看:49
本文介绍了jQuery POST,错误 405 方法不允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 IIS 7.5 托管一个 ASP.NET MVC4 Web 应用程序.调试应用程序时一切正常(我假设这是因为 Windows 身份验证).但是,当我发布应用程序并浏览它时,我收到一个 405 Method not allowed 错误:

I am trying to host an ASP.NET MVC4 web application with IIS 7.5. When debugging the app everything works fine (I'm assuming this is because of Windows Authentication). However, when I publish the app and browse to it I get a 405 Method not allowed error:

POST http://localhost/ 405 (Method Not Allowed)
send 
i.extend.ajax 
i.(anonymous function)
(anonymous function)

从我读到的内容来看,这要么是 IIS 中的处理程序映射有问题,要么是 web.config 中需要一些配置.无论哪种方式,我都没有找到正确的解决方案.谁能告诉我我的 web.config 应该在所有帖子中包含什么?和/或如何在 IIS 中设置正确的处理程序映射,因为我是 Web 开发的新手,发现选项数量有点多.

From what I've been reading this is either a problem with the Handler Mappings in IIS or some configuration is needed in the web.config. Either way, I have not found the correct solution. Could anyone tell me what my web.config should include to all POSTS? And/or how to set up the correct Handler mapping in IIS, as I am new to web development and find the number of options a bit overwhelming.

抛出错误的一段javascript如下:

The piece of javascript that throws the error is the following:

$.post("/", { latitude: locLat, longitude: locLon, username: $('#onlineUsers').attr('itemid') });

推荐答案

当请求 HTTP 动词(GET、PUT、POST、DELETE、HEAD 等)时,IIS 会抛出 405 并且不支持/不允许指定的处理程序.

A 405 is thrown by IIS when an HTTP verb(GET,PUT,POST,DELETE,HEAD,etc.) is requested and is not supported/disallowed by the designated handler.

您需要打开 IIS 管理器 -> 默认网站 -> 处理程序映射(或特定于您的网络应用程序的处理程序映射)

You'll need to open the IIS manager -> Default Web Site -> Handler Mappings (Or the handler mappings specific to your web-application)

在这里,您需要使用处理程序映射,因为其中之一不允许POST"动词.

In here you'll need to play with the handler mappings as one of them is not allowing "POST" verbs.

由于您没有发布到任何特定页面(.aspx、.ashx 等),因此很难确定导致您出现问题的确切处理程序.

As you are not posting to any specific page (.aspx, .ashx, etc.), it will be difficult to identify the exact handler that is causing you issues.

感兴趣的处理程序可能是:

Handlers of interest may be:

  • ExtensionlessUrlHandler-ISAPI-4.0_32bit/64bit
  • 静态文件

确定您的请求被路由到的处理程序后,双击它以打开对话框.

Once you identify the handler your request is being routed to, double click it to open the dialogue.

从那里点击请求限制"然后动词"

From there click "Request Restrictions" then "Verbs"

确保文本区域中存在适当的动词.

Make sure the appropriate verb is present in the text area.

正如我之前提到的,我不确定哪个处理程序正在处理您的请求,因为您没有发布到任何特定页面(您可能会重写 URL 以适当地路由您的请求).

As I mentioned before, I'm not sure which handler is handling your request as you are not posting to any particular page (you may have URL re-writing in place that is routing your request appropriately).

如果上述操作失败,您可能需要检查是否安装了 WebDAV Publishing 并将其删除(需要重新启动).

If the above fails, you may need to check if WebDAV Publishing is installed and remove it (restart required).

这篇关于jQuery POST,错误 405 方法不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆