2016-03-05 13 views
0

我有兩個主頁是不同的用戶和管理員。對於用戶而言,其Default.aspx和admin的AdminDefault.aspx。在我的Site.Master頁它包含主頁和下面其他默認頁面的默認網址,如何更改站點地圖中的另一個頁面中的網址的默認重定向頁面在C#asp.net

<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> 

當,管理員一個管理logges重定向到默認主頁

回答

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
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"); 
    } 
    } 
相關問題