2016-05-05 38 views
4

我想配置應用程序並阻止用戶直接進入應用程序中的任何頁面,而無需登錄,但任何用戶都可以訪問網站主頁。如何使用表單身份驗證將用戶重定向到特定頁面

但是當我運行網頁,登錄頁面或網站的任何頁面,我得到這個錯誤: - The requested page cannot be accessed because the related configuration data for the page is invalid.

我無法找出我會犯錯。我發佈了我的web.config文件。看看它。向我展示我犯的錯誤以及解決方案。

的web.config

<?xml version="1.0"?> 
 

 
<!-- 
 
    For more information on how to configure your ASP.NET application, please visit 
 
    http://go.microsoft.com/fwlink/?LinkId=169433 
 
    --> 
 

 
<configuration> 
 

 
    <connectionStrings> 
 
    <add name="ConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" 
 
     providerName="System.Data.SqlClient" /> 
 
    </connectionStrings> 
 

 
    <authentication mode="Forms"> 
 
    
 
    <forms loginUrl="/Registration/LoginPage.aspx"> 
 
     
 
    </forms> 
 
    
 
    </authentication> 
 
    
 

 
    <system.web> 
 
     <compilation debug="true" targetFramework="4.5.2" /> 
 
     <httpRuntime targetFramework="4.5.2" /> 
 
    </system.web> 
 
    
 
    <location path="FIRST PAGE"> 
 
     <system.web> 
 
     <authorization> 
 
      <allow users="*"/> 
 
      
 
     </authorization> 
 
     </system.web> 
 
    </location> 
 
    
 
    <location path="Registration"> 
 
     <system.web> 
 
     <authorization> 
 
      <allow users="?"/> 
 
      
 
     </authorization> 
 
     </system.web> 
 
    </location> 
 
    
 
    
 
    <location path="AdminHome"> 
 
     <system.web> 
 
     <authorization> 
 
      <allow users="admin"/> 
 
      <deny users="*"/> 
 
     </authorization> 
 
     </system.web> 
 
    </location> 
 
    
 
    <location path="Student"> 
 
     <system.web> 
 
     <authorization> 
 
      <allow roles="Student"/> 
 
      <deny users="*"/> 
 
     </authorization> 
 
     </system.web> 
 
    </location> 
 
    
 
<location path="Teacher"> 
 
     <system.web> 
 
     <authorization> 
 
      <allow roles="Teacher"/> 
 
      <deny users="*"/> 
 
     </authorization> 
 
     </system.web> 
 
    </location> 
 

 
    <appSettings> 
 

 
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/> 
 
    
 
    </appSettings> 
 
    
 

 
</configuration>

ERROR

enter image description here

enter image description here

網站的主頁是文件夾FIRST PAGE和登錄下和註冊頁面是文件夾Registration

回答

1

配置的<authentication>部分應該是<system.web>部分

MSDN authentication Element

只需編輯內部下您的web.config:

<system.web> 
    <authentication mode="Forms"> 
     <forms loginUrl="/Registration/LoginPage.aspx"> 
     </forms> 
    </authentication> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2" /> 
</system.web> 
相關問題