Tag: authorization

从ASP.NET Core 1.1 MVC迁移到2.0后,自定义cookie身份validation无法正常工作

我已经将ASP.NET Core 1.1 MVC项目迁移到ASP.NET Core 2.0,现在我注意到对应用程序的未授权部分的请求不再导致“401 Unauthorized”响应,而是导致响应的代码exception“ 500内部服务器错误”。 日志文件的示例摘录(John Smith无权访问他尝试访问的控制器操作): 2018-01-02 19:58:23 [DBG] Request successfully matched the route with name ‘”modules”‘ and template ‘”m/{ModuleName}”‘. 2018-01-02 19:58:23 [DBG] Executing action “Team.Controllers.ModulesController.Index (Team)” 2018-01-02 19:58:23 [INF] Authorization failed for user: “John Smith”. 2018-01-02 19:58:23 [INF] Authorization failed for the request at filter ‘”Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter”‘. 2018-01-02 19:58:23 [INF] Executing […]

MVC自定义身份validation,授权和角色实现

请耐心等待我提供详细信息… 我有一个MVC站点,使用FormsAuthentication和自定义服务类进行身份validation,授权,角色/成员资格等。 认证 登录有三种方式: (1)电子邮件+别名 , (2)OpenID ,以及(3)用户名+密码 。 这三个人都获得了一个auth cookie并开始一个会话。 前两个是访问者使用(仅限会话),第三个是作者/ admin使用数据库帐户。 public class BaseFormsAuthenticationService : IAuthenticationService { // Disperse auth cookie and store user session info. public virtual void SignIn(UserBase user, bool persistentCookie) { var vmUser = new UserSessionInfoViewModel { Email = user.Email, Name = user.Name, Url = user.Url, Gravatar = user.Gravatar }; […]

c#检查一个组的用户成员?

我有一个代码,用于检查用户是否是AD的成员,工作得很好, 现在我想添加检查用户是否也是组成员的可能性! 我需要修改什么来实现这一点,我做了一些工作,但它失败了! 所以这是我的代码: //Authenticate a User Against the Directory private bool Authenticate(string userName,string password, string domain) { if (userName == “” || password == “”) { return false; } bool authentic = false; try { DirectoryEntry entry = new DirectoryEntry(“LDAP://” + domain,userName, password); object nativeObject = entry.NativeObject; authentic = true; } catch (DirectoryServicesCOMException) { […]