2016-05-05 24 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> 
相关问题