asp.net web api documentation



我已经开发了一个web api项目和一个管理面板(web项目)。

我希望只有管理员用户可以访问web api文档。

web api和管理项目作为IIS中的虚拟目录托管。

有办法做到这一点吗?

我已经在管理项目的gloabl.asax中编写了代码集主体,下面是代码:

try
{
    //let us take out the username now                
    string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;
    string roles = "Admin";
    //Let us set the Pricipal with our user specific details
    HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(
        new System.Security.Principal.GenericIdentity(username, "Forms"), roles.Split(';'));
}

请协助。

您需要首先在web api项目中启用cookie身份验证。您可以在两个应用程序之间共享cookie。确保每个应用程序中的Cookie名称相同。请参阅http://www.hanselman.com/blog/SharingAuthorizationCookiesBetweenASPNET4xAndASPNETCore10.aspx

最新更新