简体   繁体   English

一个MapHttpRoute上带有IIS8.5的Web API 2错误401.0

[英]Web API 2 Error 401.0 with IIS8.5 on one MapHttpRoute

I'm making an Web API 2. 我正在制作一个Web API 2。

Debugging on my local machine works fine. 在我的本地计算机上调试正常。 VS 2013 + IIS 8.0 VS 2013 + IIS 8.0
The server is running Windows 2012 R2 + IIS 8.5 + Plesk v12 服务器正在运行Windows 2012 R2 + IIS 8.5 + Plesk v12

All my routes works fine when I debug it on my local machine. 在本地计算机上调试时,我的所有路由都工作正常。
I'm using Postman and Fiddler to check everything on the API. 我正在使用Postman和Fiddler来检查API上的所有内容。
I've got one excepting when I deploy it to the server and I send a PUT request to route http://example.net/service/Member/Profile/9 除了将其部署到服务器并发送PUT请求以路由http://example.net/service/Member/Profile/9之外,我已经收到了一个例外。
I get the following error: 我收到以下错误:

HTTP Error 401.0 - Unauthorized You do not have permission to view this directory or page. HTTP错误401.0-未经授权您无权查看此目录或页面。

Most likely causes: The authenticated user does not have access to a resource needed to process the request. 最可能的原因:经过身份验证的用户无权访问处理请求所需的资源。

Module: WebDAVModule 模块:WebDAVModule

Notification: ExecuteRequestHandler 通知:ExecuteRequestHandler

Handler: WebDAVStaticMapping 处理程序:WebDAVStaticMapping

Error Code: 0x80070005 错误代码:0x80070005

Requested URL: http://example.org/service/Member/Profile/5 要求的网址: http : //example.org/service/Member/Profile/5

Physical Path:C:\\Inetpub\\vhosts\\example.org\\httpdocs\\service\\Member\\Profile\\5 物理路径:C:\\ Inetpub \\ vhosts \\ example.org \\ httpdocs \\ service \\ Member \\ Profile \\ 5

Logon Method: Anonymous 登录方法:匿名

Logon User: Anonymous 登录用户:匿名

I checked the configuration on IIS and it's looking fine I think. 我检查了IIS上的配置,看起来不错。 The anonymous authentication is active and the other authentication methods are deactivated. 匿名身份验证处于活动状态,其他身份验证方法已停用。 The ApplicationPoolIdentity is selected. 选择了ApplicationPoolIdentity。

Code Behind the Web API 2 Web API 2背后的代码

The route is mapped like this: 路线映射如下:

config.Routes.MapHttpRoute(
            name: "EditMember",
            routeTemplate: "service/Member/Profile/{id}",
            defaults: new { controller = "Members", action = "Update", id = RouteParameter.Optional },
            constraints: null
        );

It will run this code in the controller: 它将在控制器中运行以下代码:

// PUT: service/Member/5
[ActionName("Update")]
[ResponseType(typeof(void))]
public async Task<IHttpActionResult> PutMembers(int id, MemberUpdate member)
{
    if (!ModelState.IsValid)
    {
        return BadRequest(ModelState);
    }
    IEnumerable<Members> memberSearchExist = from search in db.MembersSet
                                             where search.Id == id 
                                             select search;
    if (!memberSearchExist.Any())
    {
        return Conflict();
    }
    try
    {
        Members memberChanged = memberSearchExist.FirstOrDefault();
        memberChanged.Firstname = member.Firstname;
        memberChanged.Lastname = member.Lastname;
        memberChanged.DateOfBirth = member.DateOfBirth;
        memberChanged.Email = member.Email;

        db.Entry(memberChanged).State = System.Data.Entity.EntityState.Modified;

        await db.SaveChangesAsync();
    }
    catch (DbUpdateConcurrencyException)
    {
        if (!MembersExists(id))
        {
            return NotFound();
        }
        else
        {
            throw;
        }
    }
    return StatusCode(HttpStatusCode.NoContent);
}

I'm using CORS and it's working fine for all the other things. 我正在使用CORS,在所有其他情况下都可以正常工作。

var corsAttr = new EnableCorsAttribute("http://app.example.org, http://localhost:14844", "*", "*");
config.EnableCors(corsAttr);

Could someone help me please? 有人可以帮我吗?

Thanks in advance! 提前致谢!

The first problem is the WebDav Module. 第一个问题是WebDav模块。 The module is blocking the PUT and DELETE methods. 该模块阻止了PUT和DELETE方法。 You can resolve this by uninstall it. 您可以通过卸载解决此问题。 Here can you find how to do this: https://betimdrenica.wordpress.com/2013/02/05/web-api-on-iis-8-0-405-method-not-allowed-for-put/ 您可以在这里找到如何执行此操作的方法: https : //betimdrenica.wordpress.com/2013/02/05/web-api-on-iis-8-0-405-method-not-allowed-for-put/

The second problem was an HTTP Error 404.0 - Not Found, MapRequestHandler I found this solution: https://stackoverflow.com/a/5677618/2660428 on SO And I followed this step to install Server Side Includes http://www.iis.net/configreference/system.webserver/serversideinclude 第二个问题是HTTP错误404.0-未找到,MapRequestHandler我找到了此解决方案:SO上的https://stackoverflow.com/a/5677618/2660428并且我按照此步骤安装了服务器端包含http://www.iis达网络/ configreference / system.webserver / serversideinclude

The last problem was that I could only 最后一个问题是我只能

var corsAttr = new EnableCorsAttribute("http://app.example.org", "*", "*");
config.EnableCors(corsAttr);

Now everything is working fine. 现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM