iidentity

Set Identity of Thread

99封情书 提交于 2019-11-28 00:39:46
In C#, how do I set the Identity of a Thread? For example, if I have Thread MyThread, which is already started, can I change MyThread's Identity? Or is this not possible? Martin Brown You can set the Identity of a thread by creating a new Principal. You can use any Identity that inherits from System.Security.Principal.IIdentity , but you need a class that inherits from System.Security.Principal.IPrincipal that takes the type of Identity you are using. For simplicity sake the .Net framework provides GenericPrincipal and GenericIdentity classes which can be used like this: using System.Security

HttpContext.Current.User.Identity.Name is always string.Empty

百般思念 提交于 2019-11-27 07:16:39
Hi I use a custom MembershipProvider. I want to know the current username during an application scenario, but when I try accessing HttpContext.Current.User.Identity.Name it always returns string.Empty. if (Membership.ValidateUser(tbUsername.Text, tbPassword.Text)) { FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity.IsAuthenticated; //true string y = User.Identity.Name; //"" FormsAuthentication.RedirectFromLoginPage(tbUsername.Text, cbRememberMe.Checked); } Am I missing something? FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity

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

Set Identity of Thread

浪子不回头ぞ 提交于 2019-11-26 21:46:00
问题 In C#, how do I set the Identity of a Thread? For example, if I have Thread MyThread, which is already started, can I change MyThread's Identity? Or is this not possible? 回答1: You can set the Identity of a thread by creating a new Principal. You can use any Identity that inherits from System.Security.Principal.IIdentity, but you need a class that inherits from System.Security.Principal.IPrincipal that takes the type of Identity you are using. For simplicity sake the .Net framework provides

HttpContext.Current.User.Identity.Name is always string.Empty

牧云@^-^@ 提交于 2019-11-26 13:09:12
问题 Hi I use a custom MembershipProvider. I want to know the current username during an application scenario, but when I try accessing HttpContext.Current.User.Identity.Name it always returns string.Empty. if (Membership.ValidateUser(tbUsername.Text, tbPassword.Text)) { FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity.IsAuthenticated; //true string y = User.Identity.Name; //\"\" FormsAuthentication.RedirectFromLoginPage(tbUsername.Text, cbRememberMe.Checked); } Am

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,