如何在C#asp.net中的另一个页面中更改站点地图中URL的默认重定向页面

时间:2016-03-05 06:16:44

标签: c# asp.net site.master

我有两个主页,对于用户和管理员来说是不同的。对于用户,其Default.aspx和admin为AdminDefault.aspx。在我的Site.Master页面中,它包含主页和其他默认页面的默认URL,如下所示,

<ul id="menu">
     <li><a runat="server" id="home" href="~/">Home</a></li>
     <li><a runat="server" href="~/About.aspx">About</a></li>
     <li><a runat="server" href="~/Contact.aspx">Contact</a></li>
</ul>

当管理员登录时,管理员会重定向到默认主页

2 个答案:

答案 0 :(得分:2)

鉴于您具有以下功能来确定用户是否为管理员组的成员

bool IsInGroup(string user, string group)
{
    using (var identity = new WindowsIdentity(user))
    {
        var principal = new WindowsPrincipal(identity);
        return principal.IsInRole(group);
    }
}

然后在IF语句之后重定向是一件简单的事情,如下所示:

if(IsInGroup(User.Name, "Administrators")
    return RedirectToAction("AdminDefault.aspx");

(请注意,上面的代码示例是从内存中编写的,可能并不准确。实际上,它可能不是)

答案 1 :(得分:1)

Check Role Using session and provide condition like this


    string Role="";

    on Login button click event check the role

   YourLoginMethod()
   {
      // Your Login Code and after check
     //Pass Role in string above or Use session
     if(Role=="admin")
     {
     Response.Redirect("~/Admin.aspx");
    }
    else{
     Response.Redirect("~/Index.aspx");
    }
   }