简体   繁体   English

身份验证和授权无法正常工作

[英]Authentication & Authorization not working properly

I am first time dealing with authentication and authorization. 我是第一次处理身份验证和授权。

In my web.config i have following code for authentication & authorization: 在我的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>

And

<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 Code: .cs代码:

protected void btnLogin_Click(object sender, EventArgs e)
        {
            if(FormsAuthentication.Authenticate(txtUserName.Text,txtPassword.Text))
            {
                FormsAuthentication.RedirectFromLoginPage(txtUserName.Text,true);
            }
        }

As my expectation,when i make login from 'raj' user, it should redirect me to users.aspx , but every time its redirecting me to Default.aspx 符合我的期望,当我从“ raj”用户登录时,它应该将我重定向到users.aspx ,但是每次将其重定向到Default.aspx

Why is this working so? 为什么这样工作?

Has i made anything wrong? 我做错了什么吗?

Please help me. 请帮我。

in your web.config, in the authentication/forms section, change the defaultUrl appropriately: 在您的web.config中的authentication/forms部分中,适当地更改defaultUrl

change 更改

defaultUrl="Default.aspx"

to this: 对此:

defaultUrl="users.aspx"

about FormsAuthentication.RedirectFromLoginPage 关于FormsAuthentication.RedirectFromLoginPage

Redirects an authenticated user back to the originally requested URL 
or the default URL.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM