首页 > 解决方案 > 在 asp.net 的 web.config 中将基于角色的身份验证设置为 defaultUrl

问题描述

我的应用程序包含角色“管理员”和“用户”。如何在 web.config 文件中为具有一个默认 URL 的“用户”和具有另一个默认 URL 的“管理员”提供 web.config 设置。

我当前的 web.config 文件代码:

<authentication mode="Forms">
    <forms defaultUrl="/Welcome.aspx" loginUrl="/LogIn.aspx" >              
    </forms>        
</authentication>
<authorization>
    <deny users="?" />      
</authorization>

我的 aspx.cs 代码在登录条件下:

if (res =="USER") 
{
    Details det = new Details();
    int id = det.UserId(Email, Passwor);
    Label2.Text = id.ToString();
    Session["ID"] = Label2.Text;
    string name = det.UserName(Email, Passwor);
    Label3.Text = name;
    Session["Name"] = Label3.Text;
    Session["Role"] = TextBox1.Text;
     Response.Redirect("Welcome.aspx");
}
if (res =="ADMIN")
{
    FormsAuthentication.GetRedirectUrl(Email,true);
    //Response.Redirect("admin_page.aspx");
}

标签: c#asp.net

解决方案


推荐阅读