MVC3 + EF4 + MySQL System.Security.SecurityException:请求失败

时间:2011-12-23 12:18:07

标签: mysql asp.net-mvc entity-framework

我正在开发一个ASP.NET MVC3 Web应用程序,它使用Entity Framework 4.1和MySQL。

本地一切运行良好,但是当我将解决方案部署到Web主机时,它会给我以下错误消息:

  

System.Security.SecurityException:请求失败。在   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly   asm,PermissionSet被授予,PermissionSet被拒绝,   RuntimeMethodHandleInternal rmh,SecurityAction动作,对象需求,   IPermission permThatFailed)at   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(对象   assemblyOrString,PermissionSet被授予,PermissionSet被拒绝,   RuntimeMethodHandleInternal rmh,SecurityAction动作,对象需求,   IPermission permThatFailed)at   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet中   授予,PermissionSet拒绝,PermissionSet要求,   RuntimeMethodHandleInternal rmh,Object assemblyOrString,   SecurityAction动作,布尔值throwException)at   System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet中   demandSet,PermissionSet& alteredDemandset,   RuntimeMethodHandleInternal rmh)at   System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset,   RuntimeMethodHandleInternal rmh)at   System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32标志,   PermissionSet grantSet)at   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(的Int32   权限,PermissionSet targetGrant,CompressedStack   securityContext)at   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(的Int32   permission,PermissionSet targetGrant)失败的操作是:   需求失败的第一个权限的类型是:   System.Security.PermissionSet

我的网站.Config:

<connectionStrings>
    <add name="MySqlMembershipConnection" connectionString="Data Source=localhost;userid=userName;password=passw0rd;database=tv;" providerName="MySql.Data.MySqlClient,Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
    <add name="TvEntities" connectionString="metadata=res://*/Entities.Model.csdl|res://*/Entities.Model.ssdl|res://*/Entities.Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=127.0.0.1;port=3351;User Id=userName;password=passw0rd;Persist Security Info=True;database=tv&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

<system.data>
    <DbProviderFactories>
        <clear />
        <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
        type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

Trustlevel处于中等状态。

有什么想法吗?

3 个答案:

答案 0 :(得分:2)

尝试使用较新版本的连接器。它是reported as a bug,应该在6.3.7和6.4.1中修复。

答案 1 :(得分:2)

您可以随时切换到完全信任的其他托管服务提供商吗?

答案 2 :(得分:0)

添加对System.Web.Providers的引用。如果程序集在本地不可用,请使用NuGet Package Manager按如下方式安装它:

PM> Install-Package System.Web.Providers

还要在web.config文件中验证以下条目已添加到配置文件部分

<roleManager defaultProvider="DefaultRoleProvider">
    <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider,            
                   System.Web.Providers, Version=1.0.0.0, Culture=neutral,  
                   PublicKeyToken=31bf3856ad364e35"   
                   connectionStringName="DefaultConnection" applicationName="/" />
    </providers>
</roleManager>

然后您可以重建应用程序并执行它。