2012-11-16 25 views
-2

我使用形式的驗證後USER1日誌的其wrking fine.But在他西港島線顯示user1.aspx頁面,但訪問用戶2,如果他登陸他就可以訪問用戶2之後的URL改變頁面還這不應該發生,所以香港專業教育學院在網絡配置文件中所做的更改這樣我不應該讓用戶1通過改變URL

<authentication mode="Forms"> 
     <forms 
     name=".LOGIN" 
     cookieless="UseCookies" 
     loginUrl="LOGIN.aspx"/> 

    </authentication> 

    <authorization> 
     <deny users="?"/> 
    </authorization> 
    </system.web> 


    <location path="~/CabScheduler/User1/User1.aspx"> 
    <system.web> 
     <authorization> 
     <deny users="?"/> 
     </authorization> 
    </system.web> 
    </location> 



    <location path="~/CabScheduler/User2/User2.aspx"> 
    <system.web> 
     <authorization> 
     <deny users="?"/> 
     </authorization> 
    </system.web> 
    </location> 




    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

在登錄page--

protected void btnLogin_Click(object sender, EventArgs e) 
     { 
      bool validLogin = false; 

      validLogin = IsValidUser(txtUserName.Text.Trim(), txtPassword.Text.Trim()); 
      int UserId = FindRoleId(txtUserName.Text.Trim(), txtPassword.Text.Trim()); 
      if (validLogin) 

      {  
       FormsAuthentication.RedirectFromLoginPage(txtUserName.Text.Trim(), false); 
       if(UserId ==1) 
        Response.Redirect("~/User1/User1.aspx"); 
       else 
        Response.Redirect("~/User2/User2.aspx"); 
     } 


      else 

       lblInformation.Text = "Incorrect Login Information"; 
     } 

告訴我,我在想什麼或做錯了。 非常感謝!

+0

你有問題嗎? – Oded

+0

身份驗證不應該依賴URL。 – gdoron

+0

你沒有在任何地方進行任何授權檢查? ? – ryadavilli

回答

0

存放在Session用戶ID,而檢查的ID是有效的在這些網頁當前頁面。

Session["userId"] = UserId; 

和頁面本身:

if (Session["userId"] != xxx) 
    Redirect("somewhere"); 

請用適當的值練習I.

+1

他沒有多問什麼,以便你在回答...':)' – gdoron

0

User1.aspx OnLoad事件查看當前用戶進行身份驗證訪問此頁面或沒有和相應的處理。

在User1.aspx onLoad事件檢查:

if(UserId !=1) 
    { 
    //redirect to login page 
    } 
0

試試下面

<location path="~/CabScheduler/User2/User2.aspx"> 
    <system.web> 
     <authorization> 
       <allow users="user2" /> 
       <deny users="*, ?" /> 
     </authorization> 
    </system.web> 
    </location> 


    <location path="~/CabScheduler/User1/User1.aspx"> 
     <system.web> 
      <authorization> 
       <allow users="user1" /> 
       <deny users="*, ?" /> 
      </authorization> 
     </system.web> 
    </location> 
+0

感謝ü..但用戶仍然可以通過改變URL來訪問其他網頁 – user1799214

相關問題