【问题标题】:Authentication & Authorization not working properly身份验证和授权无法正常工作
【发布时间】:2013-05-15 07:51:50
【问题描述】:

我是第一次处理身份验证和授权。

在我的 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

为什么会这样?

我是不是做错了什么?

请帮帮我。

【问题讨论】:

    标签: c# asp.net .net visual-studio-2010 authentication


    【解决方案1】:

    在您的 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.
    

    【讨论】:

    • 但在 users.aspx 的位置路径中,我写了两个 raj nad shiv 的名称。它应该转到那个链接。不是吗?
    • 位置不是为了那个。 location 指定域的给定部分是否可以被已验证用户列表中的全部或部分或任何人查看
    猜你喜欢
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 2014-11-17
    • 2012-10-20
    • 1970-01-01
    • 2020-05-18
    • 2015-02-16
    • 1970-01-01
    相关资源
    最近更新 更多