1

ASP.NET WebForms and i am making authentication for users , but i get this error in web.config file:

Server Error in '/' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: sections are allowed only within sections.

Source Error:

Line 38: Line 39: Line 40: Line 41: Line 42:

Source File: C:\Users\dunja\Desktop\webapp1\web.config
Line: 40

Here is content of Web.Config file:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="webapp1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="constr" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog=Gy;Integrated Security=SSPI;"/>
  </connectionStrings>
  <!--
    For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime/>
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Optimization"/>
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
      </controls>
    </pages>
    <authentication mode="Forms">
      <forms defaultUrl="~/User/User.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="2880"></forms>
    </authentication>

   <location path="Admin">

      <authorization>
        <allow roles="admin"/>
        <deny users="*"/>
      </authorization>

  </location>
  </system.web>
</configuration>

Thanks to all !!

2 Answers 2

2

Your location section should be specified outside the <system.web> tag and inside the <location> section you need to add <system.web> tags. Please refer the modified config file below

<?xml version="1.0"?>

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="webapp1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="constr" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog=Gy;Integrated Security=SSPI;"/>
  </connectionStrings>
  <!--
    For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
<location path="Admin">
  <system.Web>
      <authorization>
        <allow roles="admin"/>
        <deny users="*"/>
      </authorization>
   </system.Web>
</location>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime/>
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Optimization"/>
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
      </controls>
    </pages>
    <authentication mode="Forms">
      <forms defaultUrl="~/User/User.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="2880"></forms>
    </authentication>


  </system.web>
</configuration>
Sign up to request clarification or add additional context in comments.

Comments

1

Place your location tag just before closing the configuration tag, just like this

<location path="Admin">
<system.web>
  <authorization>
    <allow roles="admin"/>
    <deny users="*"/>
  </authorization>
</system.web>

Hope this helps...!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.