将ASP.NET MVC4发布到主机后,使用角色提供程序获取配置错误

时间:2013-12-17 14:00:26

标签: asp.net asp.net-mvc asp.net-mvc-4

我正在开发一个ASP.NET MVC4 Web应用程序。我正在使用实体框架,我的数据库在我的主机中(我正在使用HostGator)。我也将RoleProvider更改为在此数据库中(而不是默认的MVC配置)。 我的网站在我的计算机上运行得很好(使用VS2012),但是当我尝试将所有网站上传到HostGator时,我得到了这个例外:

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: Exception has been thrown by the target of an invocation.

Source Error: 


Line 62:       <providers>
Line 63:         <clear />
Line 64:         <add name="RFProviders" type="RFProject.Models.Bussiness.RFProviders, RFProject" connectionStringName="RFContext" applicationName="RFProject" writeExceptionsToEventLog="true" />
Line 65:       </providers>
Line 66:     </roleManager>

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

这是我在页面来源中可以看到的例外:

<!-- 
[VerificationException]: Operation could destabilize the runtime.
   at System.Data.Entity.Core.Metadata.Edm.MetadataCollection`1.CollectionData..ctor()
   at System.Data.Entity.Core.Metadata.Edm.MetadataCollection`1..ctor(IEnumerable`1 items)
   at System.Data.Entity.Core.Metadata.Edm.StructuralType..ctor()
   at System.Data.Entity.Core.Metadata.Edm.ComplexType..ctor()
   at System.Data.Entity.Core.Metadata.Edm.MetadataItem..cctor()
[TypeInitializationException]: The type initializer for &#39;System.Data.Entity.Core.Metadata.Edm.MetadataItem&#39; threw an exception.
   at System.Data.Entity.Core.Metadata.Edm.PrimitiveType.GetEdmPrimitiveTypes()
   at System.Data.Entity.Utilities.TypeExtensions..cctor()
[TypeInitializationException]: The type initializer for &#39;System.Data.Entity.Utilities.TypeExtensions&#39; threw an exception.
   at RFProject.Models.Bussiness.RFProviders..ctor()
[TargetInvocationException]: Exception has been thrown by the target of an invocation.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at System.Web.HttpRuntime.CreatePublicInstance(Type type)
   at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
[ConfigurationErrorsException]: Exception has been thrown by the target of an invocation. (D:\...\web.config line 64)
   at System.Web.Security.Roles.Initialize()
   at System.Web.Security.RoleManagerModule.OnEnter(Object source, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
--><!-- 
This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using &lt;customErrors mode="Off"/&gt;. Consider using &lt;customErrors mode="On"/&gt; or &lt;customErrors mode="RemoteOnly"/&gt; in production environments.-->

这是我的整个web.config文件:

这是我的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>

  <connectionStrings>
    <add name="RFContext" connectionString="***" providerName="System.Data.SqlClient" />
  </connectionStrings>

  <appSettings>
    <add key="enableSimpleMembership" value="false"/>
    <add key="autoFormsAuthentication" value="false"/>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

  <system.web>
    <!--<trust level="Medium"/>-->
    <customErrors mode="Off" />
    <globalization culture="en-gb" uiCulture="auto:en-gb" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Forms">
        <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <membership defaultProvider="AspNetSqlProvider" userIsOnlineTimeWindow="20">
      <providers>
        <add connectionStringName="RFContext" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordFormat="Hashed" applicationName="RFProject" name="AspNetSqlProvider" type="System.Web.Security.SqlMembershipProvider" />
      </providers>
    </membership>
    <roleManager defaultProvider="RFProviders" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
      <providers>
        <clear />
        <add name="RFProviders" type="RFProject.Models.Bussiness.RFProviders, RFProject" connectionStringName="RFContext" applicationName="RFProject" writeExceptionsToEventLog="true" />
      </providers>
    </roleManager>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <system.data>
    <DbProviderFactories>
    </DbProviderFactories>
  </system.data>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

</configuration>

没有评论这一行:

<trust level="Medium"/>

我收到了这个错误:

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: This configuration section cannot be used at this path.  This happens when the site administrator has locked access to this section using <location allowOverride="false"> from an inherited configuration file.

Source Error: 


Line 26:   
Line 27:   <system.web>
Line 28:     <trust level="Medium"/>
Line 29:     <customErrors mode="Off" />
Line 30:     <globalization culture="en-gb" uiCulture="auto:en-gb" />

我一直在尝试这么多东西,但我不知道该怎么办...... 非常感谢!!

1 个答案:

答案 0 :(得分:1)

第一个问题似乎与实体框架有关,而不是与web.config有关。正如您在堆栈跟踪中看到的那样,正在调用提供程序的构造函数:

at RFProject.Models.Bussiness.RFProviders..ctor()

但是你有其他错误(你必须在那条线上方,而不是下面)。也许HostGator使用的Entity Framework版本存在一些问题?

第二个问题是因为某些web.config设置可以(并且是)在服务器级别定义(我想象中的IIS),有时它们可​​以设置为“不可覆盖”。这似乎是HostGator和<trust ...>设置的情况。除了和他们聊天外你什么也做不了......