由于特殊的客户要求,我们正在开发一个ASP.NET网站,其中App_Code文件夹中包含很多代码(我知道,我们也不喜欢)。
该项目正在使用.NET 4.7.1,并且在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=\"Web\" /optionInfer+" />
重新编译后,我们经常遇到这样的问题,即并非所有代码都经过了干净地重新编译,这使我们的登录中断。我能够在以下行中找到问题所在:
bool isAuthenticated = System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated // User is logged in
&& System.Threading.Thread.CurrentPrincipal.Identity is JWTAuthenticationIdentity;
在这种情况下,即使两者的类型相同,检查的第二部分也返回false,但是,标识的类型在“Assembly1”中定义,而JWTAuthenticationIdentity的类型在“Assembly2”中定义。因此,无法在两种类型之间进行转换。可以通过在web.config中应用随机更改来纠正该错误,以强制服务器重新编译。之后,通常会删除旧的程序集,因此两种类型都将再次在同一程序集中定义,并且一切都会按预期进行。
最佳答案
通过禁止IIS中的App_Pools重叠旋转,似乎可以解决我的问题。
可以通过IIS管理器GUI在“应用程序池”->“高级设置”->“禁用重叠回收”下进行设置
关于c# - App_Code编译不会清除旧程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62634887/