2021-01-03 06:47

Access denied exception with RazorEngine 3.5


We're using RazorEngine to generate emails in an ASP.Net Web Application. Since updating our code to version 3.5, the template compiling fails with the following stack trace:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

The easiest way to test this is simply to create a blank website in Visual Studio, add the RazorEngine package, and plug the basic "Hello World" sample template. With 3.4.x, the code will run just fine. I've tracked the error to the CompileType method, when the process tries to load the generated assembly in the Windows Temp folder.

C:\Windows\Temp\RazorEngine_grceyklj.1f1\CompiledRazorTemplates.Dynamic.RazorEngine_6aa243ea4a104b1f8d7036145a4c87a0.dll Event Class: File System Result: ACCESS DENIED Impersonating: DMZ\iusr_web

Note that our websites are using ASP.NET Impersonation, and the impersonated user is "iuser_web" ,from our DMZ domain. Giving this user read access to the C:\Windows\Temp\ folder on the local machines fix the problem, and the templates are generated correctly. However, I'm not sure if this is the right course of action, since this used to work perfectly in 3.4.x.

Is this a new requirement for 3.5 ?

Thanks, Shaun


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享