[英]how to change the default redirect page of a url in sitemap in another page in C# asp.net
我有两个主页,它们对于用户和管理员而言都是不同的。 对于用户而言,其Default.aspx,对于管理员而言,其AdminDefault.aspx。 在我的Site.Master页面中,它包含主页和其他默认页面的默认网址,如下所示,
<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>
管理员登录后,管理员将重定向到默认主页
鉴于您具有以下功能来确定用户是否是管理员组的成员
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");
(请记住,上面的代码示例是从内存中写入的,可能并不准确。实际上,它可能不是)
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");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.