Fix for : System.Web.HttpException: The file has not been pre-compiled, and cannot be requested

会有一股神秘感。 提交于 2021-02-07 20:03:38

问题


We published our website and everything worked fine. After few days, something strange happened. we're getting "The file 'xxx.cshtml' has not been pre-compiled, and cannot be requested."

Resetting application pool, even restarting IIS didn’t help us to resolve the problem. Even resetting the Web server machine didn't fix the problem. but when we re-copying the published files again, web site starts working again. We compared the problem website files with the new files, all are the same. nothing is missing. so every two-three days, we are getting the same error and the only way we can fix it is recopying the files again.

We even copied website when we got an error and then create another website based on those files and it works fine! Any suggestion what can cause this problem?

Thanks in advance.


回答1:


About the error

System.Web.HttpException: The file has not been pre-compiled, and cannot be requested This error will come when a reference is specified in web.config and deployment folder/site does not contain these dlls installed in the system or bin folder does not contain them(if they are private assemblies). For Example: (add assembly="Namespace1.NameSpace2, Version=x.x.x.x, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/) if your web.config contains any assemblies like this and deployed server doesnot contain these assembiles in bin or GAC, then this error will occur.


Scenarios:

Here are some possible scenarios that will generate this error:

  1. When we publish the website with the "updateable" check OFF and then copy some files on deployment location that has some markup or code in them. By putting the "updateable" check OFF we instruct the asp.net compiler to compile all the markup and code into dll files so that further on asp.net would not consider runtime compilation of content. But if it needs to (due to the presence of such content) it will throw that error.

  2. The second situation is when we have a web application configured in VS.Net to run directly off IIS (the http project) and then we publish it to the same location again with the "updateable" checked OFF. There will be development files at same location which will cause similar errors.

  3. Another situation is where we have a precompiled website and within the root folder of it we have another folder that has content for another asp.net application but isn¡¯t marked as application in IIS. ASP.Net tracks asp.net applications when running on IIS by virtual directories in IIS marked as applications. A child folder having un-compiled content within a parent application which is precompiled will again cause this error.

Source: Microsoft Support

Apparently, it is another scenario where the cause is related to missing ReportViewer .dll references


Solutions

  • Some people talks about adding manually the missing missing assembly files.

i found out one thing that while publishing the application it does not copy all of the dependent assemblies in the bin folder.So i just copied them manually to the server and now every thing is working

  • Other people, somehow fixed this installing "Microsoft Web Service Enhancements v3.0". Downlaod here. It probably provides missing required .dll

  • Here, somebody fixed it, enabling "Create a separate assembly for each page and control output" in the Deployment Options



来源:https://stackoverflow.com/questions/49868708/fix-for-system-web-httpexception-the-file-has-not-been-pre-compiled-and-cann

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