MVC3 + EF4 + MySQL System.Security.SecurityException: Request failed

て烟熏妆下的殇ゞ 提交于 2020-01-05 04:55:56

问题


I'm developing a ASP.NET MVC3 web application, which uses Entity Framework 4.1 and MySQL.

Locally all works well, but when I deploy the solution to the web host, it gives me the following error message:

System.Security.SecurityException: Request failed. at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, Object assemblyOrString, SecurityAction action, Boolean 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 flags, PermissionSet grantSet) at System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) at System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) The action that failed was: Demand The type of the first permission that failed was: System.Security.PermissionSet

My Web.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 is on Medium.

Any ideas?


回答1:


You could always switch to another hosting provider with full trust?




回答2:


Try to use newer version of the connector. It was reported as a bug and should be fixed in 6.3.7 and 6.4.1.




回答3:


Add the reference to System.Web.Providers. If the assembly is not available locally install it using NuGet Package Manager as follows:

PM> Install-Package System.Web.Providers

Also verify in the web.config file that the following entry has been added to the profile section

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

Then you can rebuild the application and execute it.



来源:https://stackoverflow.com/questions/8615986/mvc3-ef4-mysql-system-security-securityexception-request-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!