iprincipal

What is the idea behind IIdentity and IPrincipal in .NET

女生的网名这么多〃 提交于 2019-12-02 17:25:45
So, what is the purpose for existence of both IIdentity and IPrincipal , and not some IIdentityMergedWithPrincipal ? When is it not enough to implement both in same class? Also, to understand purpose, I'd like to know where this concept comes from: It is originated in .Net There is concept of Identity/Principal as design pattern, which System.Security.Principal implemented in those interfaces It is originated somewhere else and supported for compatibility Therefore, does UserPrincipal from System.DirectoryServices act similarly to IPrincipal but not implement it by accident or by intention? P

Custom Identity using MVC5 and OWIN

故事扮演 提交于 2019-12-02 15:15:54
I trying to add custom properties to the ApplicationUser for a web site using MVC5 and OWIN authentication. I've read https://stackoverflow.com/a/10524305/264607 and I like how it integrates with the base controller for easy access to the new properties. My issue is that when I set the HTTPContext.Current.User property to my new IPrincipal I get a null reference error: [NullReferenceException: Object reference not set to an instance of an object.] System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs) +127 System.Web.SyncEventExecutionStep.System.Web

Implementing IPrincipal and IIdentity in MVC with use of custom membership and role provider

烂漫一生 提交于 2019-11-30 15:43:28
问题 I'm stuck with the implementation of a custom iprincpal and iidentity object. I spend a day now for searching how to implement these right and extend it with more informations. I want to extend the Information @Context.User.Identity.Name with custom variables like full name or something else. EDIT : Now i got the following code but if i try to read @((CustomPrincipal)Context.User.Identity).Nachname I'm getting a error that System.Web.Security.FormsIdentity could not be casted to

Implementing IPrincipal and IIdentity in MVC with use of custom membership and role provider

我的未来我决定 提交于 2019-11-30 14:48:13
I'm stuck with the implementation of a custom iprincpal and iidentity object. I spend a day now for searching how to implement these right and extend it with more informations. I want to extend the Information @Context.User.Identity.Name with custom variables like full name or something else. EDIT : Now i got the following code but if i try to read @((CustomPrincipal)Context.User.Identity).Nachname I'm getting a error that System.Web.Security.FormsIdentity could not be casted to CustomPrincipal . Any ideas? public class CustomPrincipal : GenericPrincipal { public CustomPrincipal(IIdentity

Is this Custom Principal in Base Controller ASP.NET MVC 3 terribly inefficient?

半腔热情 提交于 2019-11-28 18:27:46
Despite the fact that I've been on here for a while, this is my first ever question on SO, so please be gentle with me. I'm using ASP.NET MVC 3 and I want to create a custom Principal so I can store a bit more info about the current user than is standard thus not have to go to the database too often. It's fairly standard stuff that I'm after. Let's just say email address and user id in the first instance. I have decided to store the object in the cache as I am aware that it is not advised to store it in the session. I also don't want to have to keep casting the User object, so I wanted to

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

柔情痞子 提交于 2019-11-28 18:03:51
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 these non-decorated controller/actions, HttpContext.User is set, but with a GenericPrincipal rather than

using custom IPrincipal and IIdentity in MVC3

牧云@^-^@ 提交于 2019-11-28 04:44:45
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; } } public string AuthenticationType { get { return "CustomIdentity"; } } public bool IsAuthenticated {

RoleProvider dosn't work with custom IIdentity and IPrincipal on server

两盒软妹~` 提交于 2019-11-28 04:35:33
问题 I'm using a custom IIdentity and IPrincipal in my ASP.NET MVC application via EF 4.3 as expalined here (and follow accepted answer's solution). Also, I have a custom RoleProvider . In local (using IIS Express ), it works currectly . But now, when I upload the application on a real host, it seems all users are in "admin" role! e.g. I create a user that is not in role "admin" , but it can access to all protected pages (that need "admin" role). e.g. Role.IsUserInRole always returns true . Have

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

感情迁移 提交于 2019-11-27 20:49:15
Well, I think the title is clear enough. 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.NET impersonation, then both of them might be the same as the logon user. Try to read some really good books

Is this Custom Principal in Base Controller ASP.NET MVC 3 terribly inefficient?

北战南征 提交于 2019-11-27 20:21:19
问题 Despite the fact that I've been on here for a while, this is my first ever question on SO, so please be gentle with me. I'm using ASP.NET MVC 3 and I want to create a custom Principal so I can store a bit more info about the current user than is standard thus not have to go to the database too often. It's fairly standard stuff that I'm after. Let's just say email address and user id in the first instance. I have decided to store the object in the cache as I am aware that it is not advised to