App_Code编译不会清除旧程序集 [英] App_Code compilation does not clean old assemblies

查看:39
本文介绍了App_Code编译不会清除旧程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于特殊的客户要求,我们正在开发一个ASP.NET网站,其中App_Code文件夹中包含很多代码(我知道,我们也不喜欢).

We are developing an ASP.NET Website with a whole lot of code in the App_Code folder due to a special customer requirement (I know, we don't like that either).

该项目正在使用.NET 4.7.1,并且在web.config中有以下编译器部分

The project is using .NET 4.7.1 and we have the following compiler section in our web.config

<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />

重新编译后,我们经常遇到这样的问题,即并非所有代码都经过了干净地重新编译,这使我们的登录中断.我可以在以下行中找到问题所在:

After recompilation we often have the issue, that not all code seems to be cleanly recompiled, which breaks our login among other things. I was able to track the problem down in the following line:

    bool isAuthenticated = System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated // User is logged in
                            && System.Threading.Thread.CurrentPrincipal.Identity is JWTAuthenticationIdentity;

在这种情况下,检查的第二部分返回假,即使它们是同一类型,但是,标识的类型在组件1"中定义.而JWTAuthenticationIdentity的类型在"Assembly2"中定义.因此,无法在两种类型之间进行强制转换.

The second part of the check returns false in this case, even though both are of the same type, however, the type of the Identity is defined in "Assembly1" while the type of the JWTAuthenticationIdentity is defined in "Assembly2". Therefore casting between the two types is impossible.

可以通过在web.config中应用随机更改来纠正该错误,以强制服务器重新编译.然后,通常会删除旧的程序集,因此两种类型都将再次在同一程序集中定义,并且一切都会按预期进行.

The error can be fixed, by applying a random change in the web.config or so, to force the server to recompile. Afterwards, the old assemblies are usually deleted, both types are therefore defined in the same assembly again and everything works as expected again.

推荐答案

似乎可以通过禁止IIS中的App_Pools重叠旋转来解决我的问题.

It seems like my issue can be fixed, by disallowing the overlapping rotation of App_Pools in IIS.

这可以通过IIS管理器GUI在应用程序池"下的应用程序池"中进行设置.->高级设置"->禁用重叠回收"

This can be set via the IIS Manager GUI under "App Pools" --> "Advanced Settings" --> "Disable overlapping Recycle"

这篇关于App_Code编译不会清除旧程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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