从.net 3.5升级我的web应用程序.Net4.0之后,我得到一个安全透明的规则失败我的、应用程序、透明、规则

2023-09-06 14:06:25 作者:突击男厕所

从.net 3.5升级我的web应用程序.Net4.0之后,我得到一个安全透明的规则失败。

我从来没有听说过这或将其纳入我的项目。 有没有人有任何想法,这可能是?

解决方案

从微软的知识库 KB2635463 :

  

原因   发生此问题,因为当System.Web.UI.ScriptManager类   第一次实例它建立的方法信息缓存   类组件已经加载的应用程序。当它试图   检查InstrumentedAttribute异常的构造   被抛出,不处理。

     

分辨率   为了可靠地解决此问题,实例化的一个实例   的ScriptManager在应用过程中的一个点之前启动向   第一次请求实际上是被执行,但具有组装后   所述InstrumentedAttribute已加载

     

例如,在Global.asax中增加一些新的code到的Application_Start:

 私人无效的Application_Start(HttpApplication的应用程序)
{
    如果(applicationStartupComplete)回报;
    尝试
    {
        对象OSM =新System.Web.UI.ScriptManager();
    }
    赶上(例外)
    {}
}
 

此外,帖子在asp.net论坛上透露的从微软的员工这个答案:

  vs2013在创建一个ASP.NET WEB应用程序的时候,会弹出一个选择模版的对话框,这几个模版分别有什么区别

我们已经看到了问题的结合,可能会导致这样的:

          

1)的     Web服务器有信任级别设置为低于全在机器     web.config文件(裁判)

         

2)的网络服务器不具有的AJAX文件(System.Web.Extensions程序)     安装到GAC。

        

解决方案1::设置信任级别为完全的机级别的web.config

     

解决方案2:安装AJAX文件到海关总署

     

如果清凉解决它 - 它可能只是一个时间问题加载   扩展。也许,如果你安装到GAC将解决   吧。

After upgrading my web app from .Net 3.5 to .Net4.0, I get a security transparency rules failed.

I've never even heard of this or incorporated it into my project. Does anyone have any idea what this may be?

解决方案

From Microsoft's knowledge-base KB2635463:

Cause This problem occurs because when the System.Web.UI.ScriptManager class is first instantiated it builds a cache of method information for classes in assemblies already loaded in the application. When it tries to examine the constructor of the InstrumentedAttribute the exception is thrown and not handled.

Resolution To workaround this issue reliably, instantiate an instance of ScriptManager at a point during application start up prior to the first request actually being executed but after the assembly that has the InstrumentedAttribute has been loaded.

For example, in global.asax add some new code to Application_Start:

private void Application_Start(HttpApplication application) 
{ 
    if (applicationStartupComplete) return; 
    try 
    { 
        object osm = new System.Web.UI.ScriptManager(); 
    } 
    catch(Exception)
    {}
}

Additionally, a post at the asp.net forums reveals this answer from a Microsoft employee:

We have seen a combination of issues that might cause this:

1) The webserver has the trust level set less than "Full" at the machine web.config (ref)

2) The webserver does not have the AJAX files (System.Web.Extensions) installed into the GAC.

Solution 1: Set trust level to "Full" in the machine level web.config

Solution 2: Install AJAX files into the GAC

If refreshing resolves it - it might just be a timing issue loading the extensions. Probably if you install into the GAC it will resolve it.