简体   繁体   中英

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:

<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:

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

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:

change

defaultUrl="Default.aspx"

to this:

defaultUrl="users.aspx"

about FormsAuthentication.RedirectFromLoginPage

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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