My ASP.NET App_code changes not getting picked up (or are cached??)

狂风中的少年 提交于 2019-12-01 01:44:28

问题


Help!! I have a single .cs file under a (root level) App_Code directory for the purpose of retrieving the correct template for the requested URL (it is linked to our own Content Management database). Initially, it was working fine - I could make changes to it and they were picked up by the web application OK. Then something happened (no idea what) and now whatever changes I make, they are not recognised. Even if I delete the entire App_Code directory, it makes no difference - I still seem to be picking up an earlier (cached??) version of what was in the App_Code directory. Code in the .cs file is below:

using System;
using Custom.CMS.Facade;
using Custom.CMS.BO;
public class CMHttpModule : IHttpModule
{
    code here...
}

The same problem occurs even after I have copied the website to our live server.

What I don't understand is - if I introduce a deliberate error to the .cs code, I still get a compilation error, and on successful compilation an App_Code.xxxx.dll is created under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

So what version of the App_Code is my web application actually picking up? How do I make it pick up the "correct" one?

FYI I am using C#, Visual Web Developer Express 2008 and IIS 6 web server

Any assistance would be gratefully appreciated.


回答1:


Reopening the solution also works.




回答2:


Can you right click the file, go to the properties and check the build action. It has to be set to 'Compile'.




回答3:


I'm not exactly sure how you're publishing your web application, but there are a few things you could try:

  • As mentioned previously, check that you are using project references instead of file references for the DLLs which are being built from your own C# projects. Also, check that your .cs file in the App_Code directory has its Build Action set to Compile
  • Check that all of the projects are targeting the same .NET framework: v2.0, v3.5, v4.0, or v4.5. You can check this in the Application tab of the Properties of each project. Do not use the Client Profile variation.
  • In your source code, delete your built DLLs (usually the ones in the bin and obj folders) and then use Visual Studio to perform a full build. This is the equivalent of a Rebuild (read: Clean then Build). Then, publish to your web server.
  • At the risk of stating the obvious, ensure that the web browser you are using to view your site has had its cache cleared before you hit the site.

Hope this helps.

EDIT: Just had a sudden thought: is this ASP.NET web application actually a web site? If so, then your code changes might not be recognized by the ASP.NET compiler because "if a code file is not referenced, it is not compiled."

The main difference between an ASP.NET web site vs an ASP.NET web application is that the former is typically compiled dynamically (automatically) by ASP.NET on the server the first time a request is received after the site has been installed or updated, while the latter is compiled fully into DLLs before even being published. You can read more about it in the links above.




回答4:


I had the same issue yesterday and I fixed it making sure the class libraries references on the website project are pointing to your class libraries projects (not the dll's in the bin folder).

It looks because the website is targeting .net 2.0 and the class libraries are in .net 3.5 somehow the website project ignored the rebuilt dll's and used the ones in the website project bin folder.




回答5:


@SeanW -

1) Did you try modifying your Web.Config instead of deleting it outright? The Web.Config is cached, but any revision to it should recycle your Application Cache.

2) Have you tried blowing away your whole site, and copying it out from scratch? (Especially be sure to delete and recopy any precompiled files in your bin directory.)

@Patrick -

1) Did you try deleting everything in your Temporary ASP.Net files directory?

2) If you had revisions to dependent projects in your solution (not your startup project), did you manually rebuild those dependent projects individually?

3) Do you have access to recycle the App Pool for your live web site in IIS?

4) Did you try recopying out your live web site from scratch or modifying the Web.Config in your live web site?

General App Cache Tips -

  • You can often refresh your Application Cache by making a trivial revision to your Web.Config file.

  • As discussed in this thread, Global.asax changes, bin directory changes, and App_Code changes may also trigger a refresh of the Application Pool.

  • As a long-term solution, you may wish to manage your Application Cache through a File Dependency or SQLCacheDependency Class. (Though that last suggestion may not work on shared hosting sites like GoDaddy.)




回答6:


ASP.NET Web Application has several traps. Reloading the project is one way to resolve several problems... Odd enough, indeed (call me bug)! Personally, I prefer ASP.Net Web Sites (instead of Applications) with JIT Compilation feature. FMO, it is quicker, easier and simpler way to maintain a prj.



来源:https://stackoverflow.com/questions/6385537/my-asp-net-app-code-changes-not-getting-picked-up-or-are-cached

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