.NET 4.0中的信任等级和MySQL连接 [英] .NET 4.0 Medium Trust Level and MYSQL connection

查看:242
本文介绍了.NET 4.0中的信任等级和MySQL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我认为正确的答案可以帮助很多人是具有相同problem.Because它是一种常见并不能很好回答的问题。

I have a problem and I think a proper answer will help a lot of people which is having same problem.Because it is a common and not well answered problem.

现在的问题是关于IIS.A中等信任级别配置几个月前,我codeD我的网站,我的本地机器完全信任级别的配置,当我上传到主机这是工作的罚款。 但是,我的托管公司有关于信任度的新规则,现在他们只允许中等信任级别。

The problem is about "Medium trust level" configuration in IIS.A few months ago I coded my website with "Full trust level" configuration on my local machine and when I uploaded it to host that was working fine. But my hosting company have a new rule about trust level,now they only allows "Medium trust level".

我的网页不能正常工作now.I试图去适应我的网站,但我不知道该怎么做that.And那肯定很多人也不知道.. 所以,我会告诉我做了什么,到目前为止,你能帮帮我吗?

My web page doesn't work now.I tried to adapt my website but I have no idea how to do that.And that's sure a lot of people don't know either.. So I will tell what I have done so far, can you help me?

首先,我试图去这里改变了我的本地配置,

First I tried to changed my local configuration by going here,

C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319 \ Config中

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config

和打开我的webconfig文件,并修改

and opened my webconfig file,and changed

<trust level="Full" originUrl="" />

<trust level="Medium" originUrl="" />

在这只是为了测试我创建了一个新的网站,ASP默认template.It是working.Then我加MYSQL.DLL作为参考连接到MySQL database.But它扔安全例外与堆栈:

After that just for testing I created a new website with ASP Default template.It was working.Then I add Mysql.dll as references to connect to Mysql database.But it throwed Security Exception with that stack:

[SecurityException异常:请求类型的权限   System.Security.Permissions.SecurityPermission,mscorlib程序,   版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089'   失败。] MySql.Data.MySqlClient.MySqlTrace..cctor()+ 0

[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] MySql.Data.MySqlClient.MySqlTrace..cctor() +0

那么现在怎么办?我们不能连接到mysql数据库了吗?还是有办法解决吗?我从来没有改变过我的webconfig文件的网站项目文件夹,我需要改变这里的东西吗? 请帮我家伙?

So what now? Can't we connect to mysql database anymore? Or is there a solution?I never changed my webconfig file in website project folder do I need to change something here? Please help me guys?

推荐答案

大家好我finnally找到解决我的问题,所以我会尽量帮助那些有相同problem.Partial信任和中等信任级别的人都是一样的东西。请注意,出去。

Hi everyone I finnally find solution to my problem, so I will try to help that people having same problem.Partial trust and Medium Trust level are same thing note that out.

在怀疑我的第一个步骤是绝对necessary.Don't忘记改变你的信任级别为中。之后,你需要得到正确的.Net连接器版本 的政府公报网站 小心选择你的托管服务提供商使用该版本。比如我的托管公司正在使用的MySQL Connector净6.5.4

My first step at the question is absolutely necessary.Don't forget to change your trust level to "Medium". After that you need to get right .Net Connector version from The Oficial Website Be careful to choose version that your hosting provider using. For example my Hosting company is using Mysql Connector Net 6.5.4

其次,你需要配置你的项目webconfig,将使用.dll文件,并得到下中等信任级别必要在未经许可的文件。

Secondly you need to configure your projects webconfig file that will use your .dll files and get the necessary permisson under Medium Trust Level.

您需要在添加&lt;结构&GT; 这样的事情;

You need to add under your <configuration> something like this;

 <mscorlib>
    <security>
      <policy>
        <PolicyLevel version="1">
          <SecurityClasses>
            <SecurityClass Name="MySqlClientPermission" Description="MySql.Data.MySqlClient.MySqlClientPermission, MySql.Data, Version=6.6.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
          </SecurityClasses>
        </PolicyLevel>
      </policy>
    </security>
  </mscorlib>

如果您的系统没有自动下添加你的&LT;的System.Web&GT; 您需要添加;

  <assemblies>
    <add assembly="MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
    <add assembly="MySql.Data.Entity, Version=6.5.4.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
    <add assembly="MySql.Web, Version=6.5.4.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
  </assemblies>

有时候这种步骤可能是不够的,你需要编辑在你web_mediumtrust.config的

Sometimes this steps may not be enough and you need to edit your web_mediumtrust.config under the

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config

您需要在添加此行

<SecurityClasses>
  <securityclass Name="MySqlClientPermission" Description="MySql.Data.MySqlClient.MySqlClientPermission, MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

<NamedPermissionSets>
  <iPermission class = "MysqlClientPermission" version = "1">  
    <add connectionString = "Server =; Database =;"  restrictions = "User =; User Id =; Password =; Port =; Pooling =;" KeyRestrictionBehavior = "(Prevent Usage | Allow Only)" /> 
  </iPermission>

要小心你使用的是不要忘记根据该变更线的版本。如果你仍然不能明白这一点有你一个pretty的有用的链接

Be careful about version you are using dont forget to change lines according to that. If still you can't figure that out there is a pretty useful link for you

<一个href="http://dev.mysql.com/doc/refman/5.1/en/connector-net-medium-trust.html#connector-net-medium-trust-gac"相对=nofollow>信任级别根据部分信任

这篇关于.NET 4.0中的信任等级和MySQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆