WebApi with OWIN SelfHost and Windows Authentication

谁都会走 提交于 2019-11-28 10:26:30

Your question is a little unclear on exactly how you've implemented the Windows authentication.

Enable Windows authentication:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        HttpListener listener = (HttpListener)app.Properties["System.Net.HttpListener"];
        listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;

        // ...
    }
}

Get the user in an OWIN middleware:

public async Task Invoke(IDictionary<string, object> env)
{
    OwinContext context = new OwinContext(env);
    WindowsPrincipal user = context.Request.User as WindowsPrincipal;

    //...
}

Get the user in a Web API Controller:

// In a web api controller function
WindowsPrincipal user = RequestContext.Principal as WindowsPrincipal;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!