English 中文(简体)
Asp.net Form Authentication - Principal change?
原标题:Asp.net Forms Authentication - Principal changes?

I m 存在与认证表格相矛盾的问题。 我有自己的习俗本和身份班,在签字后,我打着HttpContext。 现任。 该负责人的使用者,以及存放在藏匿处(HttpContext.Current.Cache)。 似乎在经过一段时间之后,奇怪的行为才开始。 这是我的AusthenticateRequest案手:

protected void Application_AuthenticateRequest( object sender, EventArgs e ) {
    string userName;

    var formAuthCookie = HttpContext.Current.Request.Cookies[ FormsAuthentication.FormsCookieName ];
    var isAuthenticated = HttpContext.Current.Request.IsAuthenticated;

    if ( isAuthenticated || formAuthCookie != null ) {
        if ( !isAuthenticated ) {
            var ticket = FormsAuthentication.Decrypt( formAuthCookie.Value );
            userName = ticket.Name;
        }
        else {
            userName = HttpContext.Current.User.Identity.Name;
        }

        var prin = (IPrincipal)HttpContext.Current.Cache[ userName ];

        if ( prin != null ) {
            HttpContext.Current.User = prin;
        }
    }
}

这种做法总是行得通的;习俗主从海滩上提取,并正确地输入目前的情况用户。

问题在于,当我上页时,这页。 用户财产具有通用(无作用)和形式特征。 我对发生这种情况没有任何想法。 当然,该页没有工作,因为用户没有发挥适当的作用,尽管表格Auth允许用户进入限制作用页。

为什么要取代AusthenticateRequesthandler提出的第一号原则?

问题回答

相反:

var formAuthCookie = Context.Request.Cookies[ FormsAuthentication.FormsCookieName ]; 
var isAuthenticated = Context.Request.IsAuthenticated; 

if ( isAuthenticated || formAuthCookie != null ) { 
    if ( !isAuthenticated ) { 
        var ticket = FormsAuthentication.Decrypt( formAuthCookie.Value ); 
        userName = ticket.Name; 
    } 
    else { 
        userName = Context.User.Identity.Name; 
    } 

    var prin = (IPrincipal)Context.Cache[ userName ]; 

    if ( prin != null ) { 
        Context.User = prin; 
    } 
} 




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签