登录重定向问题 [英] Login Redirect Issue

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

问题描述

我想根据自己的角色重新定向的人登录。我怀疑,因为他们尚未完全登录还没有 - 当我使用code以下,调试时的角色都上来了空?我可以窃听到了错误的情况下,可有人点我在正确的方向?

 < ASP:登录ID =LoginUserOnLoggedIn =Login1_LoggedIn=服务器
    DestinationPageUrl =〜/的Login.aspx的EnableViewState =假
        RenderOuterTable =假>&所述p为H.;
< ASP:按钮的ID =LoginButton的CssClass =提交按钮=服务器WIDTH =70
    的CommandName =登录文本=登录
        的ValidationGroup =LoginUserValidationGroup/>
&所述; / P>
< / ASP:登录>保护无效Login1_LoggedIn(对象发件人,发送System.EventArgs)
{
    //覆盖RETURNURL页面参数
    //Response.Redirect(LoginUser.DestinationPageUrl);    如果(User.IsInRole(会员))
        的Response.Redirect(〜/ AskExpert / AskQuestion.aspx);
    否则,如果(User.IsInRole(专家))
        的Response.Redirect(〜/行政/专家/ ViewQuestions.aspx);
    否则,如果(User.IsInRole(管理))
        的Response.Redirect(〜/行政/ AdminHome.aspx);
}


解决方案

您可以使用的 Roles.IsUserInRole()代替 User.IsInRole 从身份验证cookie的读取验证数据,似乎当事件被触发这个数据还没有设置。

 如果(Roles.IsUserInRole(会员))
    的Response.Redirect(〜/ AskExpert / AskQuestion.aspx);
否则,如果(Roles.IsUserInRole(专家))
    的Response.Redirect(〜/行政/专家/ ViewQuestions.aspx);
否则,如果(Roles.IsUserInRole(管理))
    的Response.Redirect(〜/行政/ AdminHome.aspx);

这样做的缺点 Roles.IsUserInRole 是,如果你使用的数据库供应商,它导致往返。

I want to re-direct people logging in based on their role. When I use the code below, the roles are coming up empty when debugging - I suspect because they haven't been completely logged in yet? I may be tapping into the the wrong event, can someone point me in the right direction?

<asp:Login ID="LoginUser" OnLoggedIn="Login1_LoggedIn" runat="server"
    DestinationPageUrl="~/Login.aspx" EnableViewState="false" 
        RenderOuterTable="false">

<p>
<asp:Button ID="LoginButton" CssClass="submitButton" runat="server" Width="70"
    CommandName="Login" Text="Log In"
        ValidationGroup="LoginUserValidationGroup" />
</p>
</asp:login>

protected void Login1_LoggedIn(object sender, System.EventArgs e)
{
    // Overrides ReturnUrl page parameter
    //Response.Redirect(LoginUser.DestinationPageUrl);

    if (User.IsInRole("Member"))
        Response.Redirect("~/AskExpert/AskQuestion.aspx");
    else if (User.IsInRole("Expert"))
        Response.Redirect("~/Admin/Experts/ViewQuestions.aspx");
    else if (User.IsInRole("Admin"))
        Response.Redirect("~/Admin/AdminHome.aspx");
}

解决方案

You could use Roles.IsUserInRole() instead. User.IsInRole reads the authentication data from the auth cookie and it seems that this data is not yet set when that event is fired.

if (Roles.IsUserInRole("Member"))
    Response.Redirect("~/AskExpert/AskQuestion.aspx");
else if (Roles.IsUserInRole("Expert"))
    Response.Redirect("~/Admin/Experts/ViewQuestions.aspx");
else if (Roles.IsUserInRole("Admin"))
    Response.Redirect("~/Admin/AdminHome.aspx");

The downside to Roles.IsUserInRole is that if you're using a database provider, it results in a roundtrip.

这篇关于登录重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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