2013-04-05 216 views
2

我目前正在嘗試創建自己的CMS系統。內容管理系統安全性?

在「/tools/default.aspx」頁面上,我登錄,登錄成功後,重定向到「/tools/cms.aspx」。

我已經使用了Windows身份驗證來阻止對文件夾的不必要的訪問,但如果我的頁面「/cms/cms.aspx」型,我可以無需登錄訪問CMS

編輯:

我禁止訪問CMS,但現在登錄無法正常工作,我仍然可以訪問其文件夾。

/tools/web.config:

<?xml version="1.0"?> 
    <configuration> 
     <system.web> 
     <authorization> 
      <deny users="?"/> 
     </authorization> 
     </system.web> 

    <location path="default.aspx"> 
     <system.web> 
     <authorization> 
      <allow users="*"/> 
     </authorization> 
     </system.web> 
    </location> 

    <location path="styles"> 
     <system.web> 
     <authorization> 
      <allow users="?"/> 
      <allow users="*"/> 
     </authorization> 
    </system.web> 
    </location> 

    <location path="images"> 
     <system.web> 
     <authorization> 
      <allow users="?"/> 
      <allow users="*"/> 
     </authorization> 
     </system.web> 
    </location> 
    </configuration> 

的web.config:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <authentication mode="Forms"> 
     <forms name="CMSLogin" loginUrl="~/tools/default.aspx" protection="All" timeout="20" path="/" /> 
    </authentication> 
    <roleManager enabled="true" /> 
    </system.web> 
</configuration> 

*刪除敏感的web.config信息

登錄身份驗證嘗試:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) 
{ 
    string userName = Login1.UserName; 
    string passWord = Login1.Password; 
    bool rememberUserName = Login1.RememberMeSet; 

    using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["websiteContent"].ConnectionString)) 
    { 
     sqlCon.Open(); 
     string SQL = "SELECT CMS_Username, CMS_Password FROM CMS_Users WHERE CMS_Username ='" + userName + "' AND CMS_Password ='" + passWord + "'"; 
     using (SqlCommand sqlComm = new SqlCommand(SQL, sqlCon)) 
     { 
      sqlComm.ExecuteScalar(); 

      if (sqlComm.ExecuteScalar() != null) 
      { 
       Response.Redirect("cms.aspx"); 
      } 
      else 
      { 
       Session["UserAuthentication"] = ""; 
      } 
     } 
     sqlCon.Close(); 
    } 
} 
+0

你也許使用'MasterPages'或'Forms Authentication'你如何在你的.config文件中有'Authentication'設置? – MethodMan 2013-04-05 15:25:14

+1

另外,當你重新發明輪子時,我還會考慮實現你自己的用戶密碼,檢查Sql Server。活動目錄,...等' – MethodMan 2013-04-05 15:30:41

+0

您的問題聽起來像您可能無意中混合了表單身份驗證和Active Directory身份驗證。我也想從.config中看到Authentication設置。 – 2013-04-05 17:35:02

回答

0

你可以請檢查其頁面加載事件中每個頁面的會話變量值是否爲空,或者您可以使用母版頁並在其加載事件中執行相同的檢查。