2013-05-15 55 views
1

我第一次处理身份验证和授权。身份验证和授权无法正常工作

在我的web.config我有以下的认证&授权码:

<authentication mode="Forms"> 
    <forms loginUrl="Authentication.aspx" timeout="30" defaultUrl="Default.aspx" cookieless="AutoDetect" > 
     <credentials passwordFormat="Clear"> 
      <user name="shiv" password="[email protected]"/> 
      <user name="raj" password="[email protected]"/> 
     </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'用户登录时,它就是sh请将我重定向到users.aspx,但每次将其重定向到Default.aspx

为什么这样工作?

我做错了什么?

请帮帮我。

回答

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. 
+0

但在位置路径为users.aspx我写了raj nad shiv的名字。它应该去那个环节。不是吗? – Freelancer

+0

位置不是为了那个。位置指定域中的给定部分是否可以被全部或部分用户查看,或者在经过身份验证的用户列表中可以查看 –

+0

ohh。非常感谢你 – Freelancer