iprincipal

How to create a CustomPrincipal globally (with and without AuthorizeAttribute)

我与影子孤独终老i 提交于 2019-11-27 11:00:57
问题 I have a custom Principal/Identity for my ASP.NET MVC4 web app. I have also created a AuthorizeAttribute to instantiate my custom principal, assigning it to httpContext.User in controllers where I require Authentication. This works great for controller/actions that have been decorated with my AuthorizeAttribute, however, for controllers that don't require authentication (but still use it if it is there), I would like to get my CustomPrincipal (and preferably through HttpContext.User) . In

using custom IPrincipal and IIdentity in MVC3

久未见 提交于 2019-11-27 05:25:47
问题 I create my own IPrincipal and IIdentity implementation as shown below: [ComVisible(true)] [Serializable] public sealed class CustomIdentity : IIdentity { private readonly string _name; private readonly string _email; // and other stuffs public CustomIdentity(string name) { _name = name.Trim(); if(string.IsNullOrWhiteSpace(name)) return; _email = (connect to database and read email and other stuffs); } public string Name { get { return _name; } } public string Email { get { return _email; } }

Implementing a Custom Identity and IPrincipal in MVC

六月ゝ 毕业季﹏ 提交于 2019-11-27 01:20:30
问题 I have a basic MVC 2 beta app where I am trying to implement a custom Identity and Principal classes. I have created my classes that implement the IIdentity and IPrincipal interfaces, instantiated them and then assigned the CustomPrincipal object to my Context.User in Application_AuthenticateRequest of the Global.asax. This all succeeds and the objects look good. When I begin to render the Views the pages are now failing. The first failure is in the default LogoOnUserControl view on the

What's the difference between HttpContext.Current.User and Thread.CurrentPrincipal in asp.net?

只谈情不闲聊 提交于 2019-11-26 20:27:53
问题 Well, I think the title is clear enough. 回答1: The biggest difference is that they do not have to be the same. Generally speaking, HttpContext.Current.User is the logon user (when it is called on a worker thread) while Thread.CurrentPrincipal is the worker process identity. On IIS 5.x, Thread.CurrentPrincipal by default is ASPNET . On IIS 6 and above, Thread.CurrentPrincipal by default is Network Service (or the application pool identity you change to). To make it complex, if you enable ASP

ASP.NET MVC - Set custom IIdentity or IPrincipal

北战南征 提交于 2019-11-25 22:23:04
问题 I need to do something fairly simple: in my ASP.NET MVC application, I want to set a custom IIdentity / IPrincipal. Whichever is easier / more suitable. I want to extend the default so that I can call something like User.Identity.Id and User.Identity.Role . Nothing fancy, just some extra properties. I\'ve read tons of articles and questions but I feel like I\'m making it harder than it actually is. I thought it would be easy. If a user logs on, I want to set a custom IIdentity. So I thought,