Solved

ASP .NET - Updating one C# code-behind file in production

Posted on 2004-10-06
9
951 Views
Last Modified: 2008-01-09
Greetings,

I have an ASP .NET web application residing on an production server. If the need arouse to make modifications to one particular C# code behind file; I would not fathom having to recompile my current development version and re-deploying the entire application to the production server (due to the possibility of having untested code currently in development..)

So I would like to know what would be the best way to update my production application if it just involved a minor change to one particular C# file?  I mean, I couldn't just copy the file over.. the entire application would have to be re-complied on the production server, right?  What is the best way to do this?


Thanks
0
Comment
Question by:muaddib2004
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:jcrumble
ID: 12239693
Running the same environment and the same code, I just copy over the top of my old files when I need to update my production app and run the piece of code to force the server to recognize the change.  Without knowing how integrated you have the code in your components, I would say that copying over the older piece of code should not present a problem.  If you have code that requires compiling you should simply have to recompile the one file and overlay it in production, not the whole app.  

In my case I setup an additional site between my development and production environment I use for testing.  Nothing elaborate, just a machine that can handle the app and allows me to test my code before moving it to production as well as allowing the users to test my changes before I make permanent changes to production.  It sounds to me like a similar environment might benefit you as well.

Good Luck,
Jeff
0
 
LVL 6

Expert Comment

by:Praesidium
ID: 12242718
Something I would consider, is any code that might be changed from time to time, put it inline in the page, instead of in a code behind file.  This compiles when the page is loaded...
0
 

Author Comment

by:muaddib2004
ID: 12244265
" If you have code that requires compiling you should simply have to recompile the one file and overlay it in production, not the whole app."


But when you compile an ASP .NET project does it not compile all .cs code behind files into one .dll?

Are you suggesting there is a way of compiling one particular .cs file into is own dll?
How would that affect the functioning of the ASP .NET application as the .dll generated by compiling the entire project already takes into account the one particular .cs file I have made code changes to?

 
0
 
LVL 4

Expert Comment

by:jcrumble
ID: 12244899
Well, that would depend on how you have your code and namespaces origanized.  If your code is contained in a single namespace then you might have problems. As Praesidium mentioned it would be better to put your code that might change from time to time inline so that it compiles when the page is loaded.  The further you go with your code in a state where it can't be changed, the more likely you are to find yourself in trouble when you have to change code.  Something else you might consider to driving as much of your changing code from a database.  I have tables that contain css classes, menu items, etc.  I don't know if this scenario fits into your site but it might be something to consider for your furture development where possible.  Also do you have to compile all your code behinds?  Granted it is faster on the webserver to compile them and call the DLL from your pages, but is it necessary everywhere in your site.  You might consider changing your code structure to allow for uncompiled code-behinds along with the compiled ones.  This would allow you to make changes to those pieces of code with just a drag and drop and run.

Good Luck,
Jeff
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:taranki
ID: 12245345
It's a bit of a hack, but you could always copy that one cs code-behind file out into another lib (another dll) change the namespace, and then change the @Page directive at the top of the page to point to your new namespace.class... I would keep the class as part of the main project though, so that the next app revision would have everything in a single lib again (make sure the changes go in both places).

/tim
0
 

Author Comment

by:muaddib2004
ID: 12245439
So.. if wish to create a new spearate dll just for the .cs file I wish to update, what would be the easiest way to do this.. Would it merely involve changing the namespace name in the c# file and recompiling my development project (which will create a new dll for the .cs file in addition to re-creating the one for the entire project.)?
0
 

Author Comment

by:muaddib2004
ID: 12245454
... and then copy the updated aspx with the newly created dll to the production server?
0
 

Accepted Solution

by:
taranki earned 125 total points
ID: 12245604
you will have to add a new project (or create a new solution and add a project).  I would add a class library project, make sure that the System.Web was in my references, add my class with a new namespace, and compile that project.  Note, this project can still be part of your total solution if you wish, but I expect this is sort of a one-off type of thing, so a new solution may be in order.

Once you compile your new project into its dll, copy it to the server, and update the @Page directive in the aspx that should use it.  Note, if you have several pages that need updating this way, you could put multiple classes in this new project, just make sure to update each aspx file accordingly.

If you have updated aspx files, then just make sure that their @Page points to your new namespace and classes, and copy them up to your server with the new dll.  The dll goes side-by-side with your existing project in the /bin directory, and your aspx's go wherever, to replace your existing ones.

I hope that clarifies a bit...
/tim
0
 

Author Comment

by:muaddib2004
ID: 12245757
"You might consider changing your code structure to allow for uncompiled code-behinds along with the compiled one"

Is it possible to include uncompiled .cs codebehind files..?  I thought IIS would not know what to do with a .cs source file
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now