相关疑难解决方法(0)

Asp.NET Web API - 405 - 不允许用于访问此页面的HTTP动词 - 如何设置处理程序映射

我使用ASP.NET Web API编写了REST服务.我正在尝试发送HttpDelete请求,但是我收到以下错误:

405 - 不允许用于访问此页面的HTTP动词

我认为我接近解决方案,我发现我应该启用IIS远程管理,转到Handler Mappings部分并将DELETE动词添加到适当的位置......但问题是有很多不同的位置列表......(就像这里:http://www.somacon.com/p126.php).

我应该编辑哪一个?其中很少没有扩展,例如"ExtensionUrlHandler-Integrated-4.0",我添加了DELETE动词,但它仍然不起作用......

修改那个只是在黑暗中拍摄,所以我应该修改不同的位置吗?如果是这样,哪一个?或者还有什么我应该做的?

相同的Web服务在我的本地服务上工作得很好,所以我猜问题是远程IIS ...

问候

asp.net iis asp.net-mvc iis-7 asp.net-web-api

95
推荐指数
6
解决办法
8万
查看次数

在IIS7上启用跨源资源共享

我最近遇到了将Javascript请求发布到另一个域的问题.默认情况下,不允许将XHR发布到其他域.

按照http://enable-cors.org/的说明,我在其他域上启用了此功能.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
      <add name="Access-Control-Allow-Headers" value="Content-Type" />
    </customHeaders>
  </httpProtocol>
 </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在一切正常,但是在发回工作200响应之前仍然会返回405响应.

Request URL:http://testapi.nottherealsite.com/api/Reporting/RunReport
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Access-Control-Request-Headers:origin, content-type, accept
Access-Control-Request-Method:POST
Connection:keep-alive
Host:testapi.nottherealsite.com
Origin:http://test.nottherealsite.com
Referer:http://test.nottherealsite.com/Reporting
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Response Headersview source
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Origin:*
Allow:POST
Cache-Control:private
Content-Length:1565
Content-Type:text/html; charset=utf-8
Date:Tue, 18 Sep 2012 14:26:06 GMT …
Run Code Online (Sandbox Code Playgroud)

javascript iis-7 xmlhttprequest cors

84
推荐指数
6
解决办法
18万
查看次数

MVC-Web API:不允许使用405方法

所以,我陷入了一种奇怪的行为,也就是说,我能够使用Postman (plugin of chrome)或使用发送(或POST)数据RESTClient(extension of Firefox),

在此输入图像描述

但是无法从我位于项目之外的html文件中发送它.当我在chrome中打开html时显示以下错误:

OPTIONS http://localhost:1176/api/user/ 405 (Method Not Allowed)
XMLHttpRequest cannot load http://localhost:1176/api/user/. Invalid HTTP status code 405 
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么会这样.以下是详细信息,您可能需要帮我解决我的错误:

UserController.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebAPIv2.Models;

namespace WebAPIv2.Controllers
{
    public class UserController : ApiController
    {
        static IUserRepository userRepository = new UserRepository();

        [HttpGet]
        public List<TableUser> GetAllUsers()
        {
            return userRepository.GetAll();
        }

        [HttpGet]
        public HttpResponseMessage GetUser(int id)
        {
            TableUser user = userRepository.Get(id);
            if (user == null)
            { …
Run Code Online (Sandbox Code Playgroud)

html c# json asp.net-web-api2

11
推荐指数
2
解决办法
6万
查看次数

如何使用参数 [FromBody] 从 C# 发出 HTTP Patch 请求

我正在创建一个 Web API 服务,但在调用 HTTP 补丁请求时遇到一些问题。尽管我知道如何创建它们。如果您能帮助我,我将不胜感激,这是我的代码:

HTTP 补丁代码:

[HttpPatch("{username}")]
        public async Task<ActionResult> Patch(string username, [FromBody] JsonPatchDocument<User> patchDocument)
        { 
            //If no info has been passed, this API call will return badrequest
            if (patchDocument == null)
                return BadRequest();

            var theUser = await connection.GetAUser(username);
            var originalUser = await connection.GetAUser(username);

            if (theUser == null)
                return NotFound();

            //Changes specified in the patchdocument are applied to the user
            patchDocument.ApplyTo(theUser, ModelState);
            //check if the patching has been successful or not
            bool isValid = TryValidateModel(theUser);

            if (!isValid)
                return …
Run Code Online (Sandbox Code Playgroud)

c# api rest patch httprequest

1
推荐指数
1
解决办法
1万
查看次数