ASP.NET Web API Self-Host with Windows Authentication

前端 未结 9 1223
不知归路
不知归路 2021-01-30 11:31

I am trying to use the ASP.NET Web API Self-Host option with Windows authentication so I can determine the logged on user and ultimately accept or reject the user based on their

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 12:02

    Are you sure you're getting through the authentication part? You could use fiddler to check whether the requests are actually going through or whether the server always responds with 401 Unauthorized (since you're using authentication).

    You could also try to implement your own custom AuthorizeAttribute and put breakpoints in it to make sure it gets hit (you'll want to override the OnAuthorization method and see if that gets hit).

    using System.Web.Http;
    public class MyAuth : AuthorizeAttribute
    {
        public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            base.OnAuthorization(actionContext); //put breakpoint here
        }
    }
    

    Also, make sure you're using the Authorize attribute from System.Web.Http, and not from System.Web.Mvc. See here why.

提交回复
热议问题