![](/img/trans.png)
[英]Authentication Filter not working with Authorization Filter in Web API
[英]Authentication & Authorization not working properly
我是第一次处理身份验证和授权。
在我的web.config中,我具有以下用于身份验证和授权的代码:
<authentication mode="Forms">
<forms loginUrl="Authentication.aspx" timeout="30" defaultUrl="Default.aspx" cookieless="AutoDetect" >
<credentials passwordFormat="Clear">
<user name="shiv" password="abc@123"/>
<user name="raj" password="abc@123"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
和
<location path="Admin.aspx">
<system.web>
<authorization>
<allow users="shiv"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<location path="users.aspx">
<system.web>
<authorization>
<allow users="shiv"/>
<allow users="raj"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
.cs代码:
protected void btnLogin_Click(object sender, EventArgs e)
{
if(FormsAuthentication.Authenticate(txtUserName.Text,txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,true);
}
}
符合我的期望,当我从“ raj”用户登录时,它应该将我重定向到users.aspx
,但是每次将其重定向到Default.aspx
为什么这样工作?
我做错了什么吗?
请帮我。
在您的web.config中的authentication/forms
部分中,适当地更改defaultUrl
:
更改
defaultUrl="Default.aspx"
对此:
defaultUrl="users.aspx"
关于FormsAuthentication.RedirectFromLoginPage
Redirects an authenticated user back to the originally requested URL
or the default URL.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.