我试图使用web.config连接到MySQL,并使用了MySQL网站配置。问题是它会使我的网站在运行时显示错误,而不是运行它。:D
这是我的web.config SQL连接:
<connectionStrings>
<remove name="LocalMySqlServer" />
<add name="LocalMySqlServer" connectionString="password=PASS****;user id=9b443f_users;server=MYSQL5008.myWindowsHosting.com;database=db_9b443f_users" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<system.web>
<sessionState mode="Custom" cookieless="true" regenerateExpiredSessionId="true" customProvider="MySqlSessionStateProvider">
<providers>
<add name="MySqlSessionStateProvider" type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="Sessions" description="Sessions" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enableExpireCallback="False" />
</providers>
</sessionState>
<profile defaultProvider="MySQLProfileProvider">
<providers>
<remove name="MySQLProfileProvider" />
<add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="Profiles" description="Profiles" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enableExpireCallback="False" />
</providers>
</profile>
<membership defaultProvider="MySQLMembershipProvider">
<providers>
<remove name="MySQLMembershipProvider" />
<add name="MySQLMembershipProvider" type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="MemRecords" description="MySQL default application" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enableExpireCallback="False" enablePasswordRetrieval="False" enablePasswordReset="True" requiresQuestionAndAnswer="True" requiresUniqueEmail="True" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="MySQLRoleProvider">
<providers>
<remove name="MySQLRoleProvider" />
<add name="MySQLRoleProvider" type="MySql.Web.Security.MySQLRoleProvider, MySql.Web, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="Roles" description="Roles" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="False" autogenerateschema="True" enableExpireCallback="False" />
</providers>
</roleManager>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="false" />
<authentication mode="Forms">
<forms loginUrl="default.aspx" />
</authentication>
</system.web>
这是它显示给我的堆栈跟踪:
[InvalidOperationException:未能映射路径"/"。]
System.Web.Configuration.ProcessHostConfigUtils.MapPathActual(字符串siteName,VirtualPath路径)+224
System.Web.Configuration.ProcessHostMapPath.MapPathCaching(字符串siteID,VirtualPath路径)+865
System.Web.Configuration.ProcessHostMapPath.GetPathConfigFilenameWorker(字符串siteID,VirtualPath路径,字符串&目录,字符串&baseName)+13
System.Web.Configuration.ProcessHostMapPath.System.Web.Configuration.IConfigMapPath.GetPathConfigFilename(字符串siteID,字符串路径,字符串&目录,字符串&baseName)+37
System.Web.Configuration.HostingPreferredMapPath.GetPathConfigFilename(字符串siteID,字符串路径,字符串&目录,字符串&baseName)+75
System.Web.Configuration.WebConfigurationHost.GetStreamName(字符串configPath)+9844796
System.Configuration.Interal.DelegatingConfigHost.GetStreamName(字符串configPath)+11
System.Configuration.BaseConfigurationRecord.InittConfigFromFile()+134[ConfigurationErrorsException:加载配置文件:无法映射路径"/"。]
System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(布尔ignoreLocal)+66566
System.Configuration.BaseConfigurationRecord.SthrowIfParseErrors(ConfigurationSchemaErrorsschemaErrors)+34 System.Configuration.Configuration.ctor(字符串locationSubPath,类型typeConfigHost,对象[]hostInitConfigurationParams)+328
System.Configuration.Interal.InteralConfigConfigurationFactory.System.Configuration.Internal.IInternalConfigConfigurationFactory.Create(TypetypeConfigHost,Object[]hostInitConfigurationParams)+29
System.Web.Configuration.WebConfigurationHost.OpenConfiguration(WebLevelwebLevel,ConfigurationFileMap fileMap,VirtualPath路径,字符串站点,字符串位置子路径,字符串服务器,字符串用户名,字符串密码,IntPtr tokenHandle)+387
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(字符串路径)+76
MySql.Web.SessionState.MySqlSessionStateStore.Initialize(字符串名称,NameValueCollection配置)+437
System.Web.Configuration.ProviderHelper.InstantiateProvider(ProviderSettingsproviderSettings,Type providerType)+597
System.Web.SessionState.SessionStateModule.SecureInstantiateProvider(ProviderSettings设置)+43
System.Web.SessionState.SessionStateModule.InitCustomStore(SessionStateSectionconfig)+87
System.Web.SessionState.SessionStateModule.InitModuleFromConfig(HttpApplication应用程序,SessionStateSection配置)+99777245
System.Web.SessionState.SessionStateModule.Init(HttpApplication应用程序)+159 System.Web.HttpApplication.InitModulesCommon()+80 System.Web.HttpApplication.InitModules()+64
System.Web.HttpApplication.InitInternal(HttpContext上下文,HttpApplicationState状态,MethodInfo[]处理程序)+792
System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext上下文)+336
System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext上下文)+107
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)+525
我刚刚发现,如果我注释掉这些行,错误就不会出现,网站也会正常工作:
<sessionState mode="Custom" cookieless="true" regenerateExpiredSessionId="true" customProvider="MySqlSessionStateProvider">
<providers>
<add name="MySqlSessionStateProvider" type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="Sessions" description="Sessions" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enableExpireCallback="False" />
</providers>
</sessionState>
我该如何修复它,这样我就不必对此发表评论了?
编辑:
使用"MySQL网站配置"并修复了错误。