OnLoggedIn在登录页ASP.NET事件 [英] OnLoggedIn event on Login page ASP.NET

查看:252
本文介绍了OnLoggedIn在登录页ASP.NET事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要根据他们在asp.net成员资格提供者的角色来重定向的人。我在OnLoggedIn登录页上的一些事件code。以下是我试过到目前为止,并没有什么不工作:

I want to redirect people according to their role in the asp.net membership provider. I have some code in 'OnLoggedIn' event on the login page. Here is what I tried so far, and nothing doesn't work:

在code以下的回报在.IsAuthenticated步假的,它说用户没有通过验证。在这一步登录页面的用户进行身份验证,我认为'OnLoggedIn事件就是这样做的正确的地方。

The code below returns false on the .IsAuthenticated step, it says the user is not authenticated. On which step at the login page the user is authenticated, I thought the 'OnLoggedIn' event is the right place to do this.

if (HttpContext.Current.User != null)
{
    if (HttpContext.Current.User.Identity.IsAuthenticated)
    {
        if (HttpContext.Current.User.Identity is FormsIdentity)
        {
        }
    }
}

我试图

第二件事就是获得该用户的所有角色,但它不返回任何东西,返回字符串空数组,我检查了角色分配给特定的用户数据库。这里是我正在尝试:

2nd thing I tried was to get all the roles for the user, but it doesn't return anything, returns empty array of strings, and I checked the database that the role is assigned to that specific user. Here is how I am trying:

string[] userRole = Roles.GetRolesForUser(LoginUser.UserName);

所以,我的问题是我如何能得到在登录页面上的角色,我需要检查在其他一些事件或其他方式。
感谢您的帮助提前,Laziale

So, my question is how I can get the role on the login page, do I need to check that in some other event or on some other way. Thanks for your help in advance, Laziale

推荐答案

第一种情况不会工作,因为它返回它排在请求的值。登录与FormsAuthentication基本上只是套在响应一个cookie如此该的下次的请求得到正确的用户。

The first situation won't work because it returns the value of the Request as it came in. Logging in with FormsAuthentication basically just sets a cookie in the Response so that the next Request gets the right User.

第二种情况的的工作虽然,假设LoginUser是您的登录控件的名称。

The second situation should work though, assuming that LoginUser is the name of your login control.

这篇关于OnLoggedIn在登录页ASP.NET事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆