简体   繁体   English

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

[英]Getting an Configuration Error with the Role Provider after publishing my ASP.NET MVC4 to host

I'm developing an ASP.NET MVC4 web application. 我正在开发一个ASP.NET MVC4 Web应用程序。 I'm using entity framework, and my database is in my host (i'm using HostGator). 我正在使用实体框架,并且数据库在主机中(我正在使用HostGator)。 I changed the RoleProvider to be in this database as well (instead of the default MVC configuration). 我也将RoleProvider更改为也包含在此数据库中(而不是默认的MVC配置)。 My website works just fine in my computer (using VS2012), but when I tried to upload all the website to HostGator, i'm getting this exception: 我的网站在我的计算机上运行正常(使用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

This is the exception i can see in the source of the page: 这是例外,我可以在页面的源中看到:

<!-- 
[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.-->

and this is my whole web.config file: 这是我的整个web.config文件:

And this is my web.config file: 这是我的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>

Without commenting this line: 不评论此行:

<trust level="Medium"/>

i'm getting this error: 我收到此错误:

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" />

Iv'e been trying so many things, but I just don't know what should I do... Thanks a lot!! 我一直在尝试很多事情,但是我不知道该怎么办……非常感谢!

The first problem seems to be related to Entity Framework rather than the web.config. 第一个问题似乎与实体框架有关,而不是与web.config有关。 As you can see in the stack trace the constructor for your provider is being called: 正如您在堆栈跟踪中看到的那样,正在调用提供程序的构造函数:

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

but then you have other errors (you have to look above that line, not below). 但随后您还有其他错误(您必须在该行的上方而不是下方)。 Maybe some problem with the Entity Framework version used by HostGator? HostGator使用的Entity Framework版本可能有问题吗?

The second problem is because some web.config settings can be (and are) defined at server level (IIS here I imagine) and sometime they can be set as "non-overridable". 第二个问题是因为某些web.config设置可以在服务器级别(我想象中的IIS)进行定义,并且有时可以将它们设置为“不可覆盖”。 This seems to be the case with HostGator and the <trust ...> setting. HostGator和<trust ...>设置似乎是这种情况。 Nothing you can do except have a chat with them... 除了与他们聊天之外,您无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM