简体   繁体   中英

How to redirect a user to a Specific Page with Forms Authentication

I want to configure the application and prevent the user from going directly to any page in the application without signing in but any user can access the websites homepage.

But when I run the homepage ,login page or any page of the website, I am getting this error:- The requested page cannot be accessed because the related configuration data for the page is invalid.

I can't find out where I am making mistake. I have posted my web.config file . have a look over it .show me where I am making mistake and what is the solution.

 <?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> 

在此输入图像描述

在此输入图像描述

the homepage of the website is under the folder FIRST PAGE and login and register page is under the folder Registration

The <authentication> part of your configuration should be inside the <system.web> section

MSDN authentication Element

Just edit your 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM