Rendering a control generates security exception in .Net 4

二次信任 提交于 2019-12-23 02:36:14

问题


I am having a problem with code that worked fine in .NET 2.0 but is giving this error under .Net 4.

Build (web): Inheritance security rules violated while overriding member: 'Controls.RelatedPosts.RenderControl(System.Web.UI.HtmlTextWriter)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

This is in DotNetBlogEngine. There were several other security demands in the code that .NET 4.0 doesn't seem to like. I followed some of the advice I found on blogs (and here) and got rid of all the other errors. But this one still eludes me.

The Main BlogEngine core dll is not set for security demands any longer and is compiled for .NET 4.0 as well.

This error is in the website side attempting to use the dll. There are controls that call a RenderControl method taking an HtmlTextWriter. Apparently the text writer now has some soft of security attributes set on it.

Each of the controls implements a custom interface ( public interface ICustomFilter ), there are no security permissions present or demands. The site is running full trust on my local dev machine.

Update:

I have tried the various settings under the security namespace in .NET 4 I read about here. I know this is a code access security change, but I don't understand the why behind it not working (or the error message).


回答1:


Set this attribute [assembly: SecurityRules(SecurityRuleSet.Level1)]

ref: http://msdn.microsoft.com/en-us/library/dd233102%28VS.100%29.aspx




回答2:


The only thing I needed to do to run under .net 4.0 was to add a reference to System.Web.ApplicationServices to the Core project.



来源:https://stackoverflow.com/questions/2768281/rendering-a-control-generates-security-exception-in-net-4

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