Click here to Skip to main content
15,898,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
There are 5 folders :-
1) AdminHome
2) FIRST PAGE : contain homepage of the website
3) Registration : contain Login and signup page
4) Student
5) Teacher

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

What I have tried:

web.config

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

HTML
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:
Module	   IIS Web Core
Notification	   Unknown
Handler	   Not yet determined
Error Code	   0x80070032
Config Error	   The configuration section 'authentication' cannot be read because it is missing a section declaration
Config File	   \\?\E:\Way2Success\web.config
Requested URL	   http://localhost:53902/Registration/LoginPage.aspx
Physical Path	   
Logon Method	   Not yet determined
Logon User	   Not yet determined
Request Tracing Directory	   C:\Users\Dixit\Documents\IISExpress\TraceLogFiles\

Config Source:
   14: 
   15:   <authentication mode="Forms">
   16:     

More Information:
This error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.
If you see the text "There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined", this error is because you are running a .NET Framework 3.5-based application in .NET Framework 4. If you are running WebMatrix, to resolve this problem, go to the Settings node to set the .NET Framework version to ".NET 2". You can also remove the extra sections from the web.config file.
View more information »
Posted
Updated 5-May-16 20:39pm

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



Just edited the web.config:

HTML
<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>
 
Share this answer
 
v3
A simple way to solve this problem is using authentication process in login page and checking authentication details in pages from AdminHome, Student, Teacher at page load.

When authentication is successful in login page, redirect user as per role to corresponding folder/page. Before redirecting, save required user credentials in session and cookie variables. Then cross check user at related pages in above mentioned folder using this values from session and cookies. If you are using master page, then you need to check required authentication details only once in master page load event. If user details does not match, simply redirect user to either login page or home page.

Following code snippet is used for login;

C#
Session["DynamicID"] = dynamic_id;
               Session["EmailID"] = txtbx_EmailID.Text.Trim();
               Session["DispName"] = GetDispName();

               app_cookie = new HttpCookie("App", dynamic_id);

               Response.AppendCookie(app_cookie);
               Response.RedirectPermanent("~/Dept/Default.aspx",true);


Following code block is used at master page load event;

C#
ses_autoid = Session["DynamicID"].ToString();
           cook_autoid = Request.Cookies.Get("App").Value.ToString();
           if (ses_autoid == cook_autoid)
           {
               Label_User.Text = "Display name: " + Session["DispName"].ToString();
               Label_User1.Text = Session["DispName"].ToString();
           }
           else {
               Response.RedirectPermanent("~/Common/LogOut.aspx", true);
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900