我已经开发了一个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(';'));
}请协助。
发布于 2016-12-14 17:18:38
您需要先在web api项目中启用cookie身份验证。您可以在两个应用程序之间共享cookie。确保每个应用程序中的Cookie名称相同。请参考http://www.hanselman.com/blog/SharingAuthorizationCookiesBetweenASPNET4xAndASPNETCore10.aspx
https://stackoverflow.com/questions/36283273
复制相似问题