第一次使用微软的企业库就遇上麻烦

情况是这样的,看了一段时间的Enterprise Library后,终于决定不用原来的SQLHelper,改用Enterprise Library Data Access Application Block来代码原来的方案。在公司完成大部分工作,做了简单的测试,顺利执行。
可是在我觉得一切就绪的时候,在家里的机器上执行在公司写的测试代码的时候却发现执行的时候总是报告说

安全性异常
说明: 应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别。

异常详细信息: System.Security.SecurityException: 不允许所请求的注册表访问权。

我家里的机器上没有装Enterprise Library,于是担心是不是跟这个有关,试着装了一下(June2005版),发现还是不行。

真是头大了,不会这么不顺利吧。于是上博客园寻求帮助,还好经过一番努力找到了解决办法,并测试成功。正面是主要步骤:

解决方案:
1、去掉这些代码。(这会是一个痛苦的经历,代码割舍不清呀)
2、给IUSR 帐户访问注册表的权限(安全问题呀!)
我们当然不推荐这2个做法:

我们推荐的做法:重新编译 Microsoft.Practices.EnterpriseLibrary.Common 项目,编译时把其中 Conditional Compilation Constants 设置中除 DEBUG;TRACE 外的其他项都去掉。

具体步骤:

1. Open Start->programs->MS Patterns and Practices -> Ent Lib -> App Blocks -> Ent Lib.Sln.

2. Take your own sweet time to minimize all the folder(s) in ur solution window.

3. Rt Clk on the “Common” project and go to “Properties”

4. In the “Configuration Properties” go to the “Build” option.

5. In the Conditional Build section of the property grid, remove everything except “DEBUG;TRACE”

6. Close everything and recompile.

    Remember...on compilation nothing will go to your common bin folder. I just plainly used the “Copy Assemblies to bin directory” option in my Start->programs->MS Patterns and Practices -> Ent Lib  part of my menu.


Now...just to be sure....de-reference your existing references to the entlib and add references again.....and woala.....you are done.


上面的英文比较简单,结合自己的环境注册对照一下就可以了。如果谁有问题,跟我联系。[email protected]
希望其他人再遇到这个问题进不要再走弯路。

转载于:https://www.cnblogs.com/jianjunli/archive/2005/11/24/283258.html

猜你喜欢

转载自blog.csdn.net/weixin_34132768/article/details/93714172