ASP.NET WebForms我正在为用户进行身份验证,但我在web.config文件中收到此错误:
>应用程序中的服务器错误。配置错误
描述:处理a期间发生错误 服务此请求所需的配置文件。请查看 以下具体错误详细信息并修改您的配置文件 适当。
分析器错误消息:仅允许部分内容 部分。
来源错误:
第38行:第39行:第40行:第41行:第42行:
源文件: C:\ Users \用户dunja \桌面\ webapp1 \ web.config中
行:40
以下是Web.Config文件的内容:
<?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>
感谢所有!!
答案 0 :(得分:1)
您的位置部分应在<system.web>
标记之外和<location>
部分内指定,您需要添加<system.web>
标记。请参阅下面的修改后的配置文件
<?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>
答案 1 :(得分:0)
在关闭配置标记之前放置位置标记,就像这样
<location path="Admin">
<system.web>
<authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
</system.web>
希望这有助于......!