![](/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.