c# - 在 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");
}
解决方案
推荐阅读
- xml - xsd 验证失败 - 引用本地 xsd 文件
- powershell - 使用相同代码的 Powershell 5.1 和 Powershell 7 证书加密之间的区别
- typescript - TypeScript中基于字符串的类型条件参数
- ruby-on-rails - 有人可以提供一个带有多个图像的神社/铁轨示例吗?
- python - 为什么会打印出这么多回复?
- c# - C#在自动驾驶仪上将httpclient post转换为restsharp post而没有异步方法
- google-sheets - 带有列选择的查询 + 导入范围以显示匹配未显示的条件
- visual-studio-code - 有没有办法通过智能感知在 vs 代码中获取悬停时提供的文本?
- python - 检查数据框中的列是否处于纪元时间会给出不同的结果
- reactjs - 如何编写反应钩子 HOC