Skip to main content
 首页 » 编程设计

c#之Web.config 中的 "The attribute ' connectionStringName ' is missing or empty."

2024年01月28日33shangdawei

我的 Web.config 文件突然出现以下错误,我不明白这是什么意思:

Parser Error Message: The attribute 'connectionStringName' is missing or empty.

Line 24:       <providers> 
Line 25:         <clear /> 
Line 26:        <add name="SMDPortalMembershipProvider" type="SMDPortalMembershipProvider" /> 
Line 27:       </providers> 
Line 28:     </membership> 

Source File: c:\inetpub\wwwroot\web.config Line: 26

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

这是我的配置文件:

<?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="ApplicationServices" 
      connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" 
      providerName="System.Data.SqlClient"/> 
  </connectionStrings> 
  <system.web> 
    <compilation debug="true" targetFramework="4.0"> 
      <assemblies> 
        <add assembly="UODOTNET, Version=2.2.5.7444, 
          Culture=neutral, PublicKeyToken=335F3FBD4BE82339"/> 
        <add assembly="System.Core, Version=4.0.0.0, 
          Culture=neutral, PublicKeyToken=B77A5C561934E089"/> 
      </assemblies> 
    </compilation> 
    <authentication mode="Forms"> 
      <forms loginUrl="Default.aspx" timeout="2880" /> 
    </authentication> 
    <authorization> 
      <deny users="?" /> 
    </authorization> 
    <membership defaultProvider="SMDPortalMembershipProvider"> 
      <providers> 
        <clear /> 
        <add name="SMDPortalMembershipProvider" type="SMDPortalMembershipProvider" /> 
      </providers> 
    </membership> 
    <customErrors mode="Off"/> 
    <sessionState cookieName="smd_portal_session" timeout="100"/> 
  </system.web> 
  <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
  </system.webServer> 
</configuration> 

当我加载 Default.aspx 页面时没有错误,但是只要我的代码调用 Membership 类,我就会收到错误。

请您参考如下方法:

您的成员(member)提供者的配置部分需要一个 connectionStringName 属性。如果没有 connectionStringName,它就不知道要在哪个数据库中查找成员信息。

您需要将 connectionStrings 部分中的连接字符串之一的名称添加到第 26 行的 add 标记中。

为了使您的 Web.Config 有效,connectionStringName 属性是必需的。没有它,您将无法使用 Membership 类。