Related
Good day
I moved to another company from a previous one, they task me to modify a existing system with a horrific code, but with patience and dedication, I managed to update the system, but I was shocked that they told me to put the source code on the system and it will be the one that the app in IIS will read. It will read the debug folder of the project. On my previous employer what we do is to publish the file, and that be one to read, but on my current employer,they put the whole source code on the web server.
Is this okay? Or am I right it's a bad practice, well other frameworks put the whole file on the server, so it should be good? Is it?
Thanks and regards
As pointed out, this was a common set.
And after all, why bother to do some whole big publish when you JUST need to modify say a bit of markup in a web page.
So, for those who have the web server "on site", then often they would point VS to the site, and open it directly.
So, to manage/use/work with such a project?
You don't use from vs file->open project, but in fact use file->open web site. At this point, it is assumed you browse directly to the folder that holds the web site - often the live web site.
There are several significant issues to be aware of.
the app in IIS will read. It will read the debug folder of the project.
That is a not a correct assumption, or even correct view. There is no such thing as a "debug" folder. Then again, be it a console app, desktop, or whatever? Sure, when you COMPILE code, it goes to the bin/debug or bin/release folder.
But, you failing to grasp that by using the "web site" option, VS does NOT do the code compile!!! (IIS does!!!). While testing in vs, then vs will do the compile, but if you are modifying the web site directly, then all you have to do is open a web page, and when you hit ctrl-s, you are done - it is now live. And this ALSO applies to code behind.
So, you can open up say the code behind page. Modify one line of code and hit ctrl-s - you are done!!!
So, yes, as you note, a lot of web site(s) were managed this way.
So, the upside is no real deployment is required. And for a larger site, this actually can be a benefit.
However, the downsides are significant, and you VERY much need to be aware of these issues.
First up, careful if you adopt Rosyln extensions. That means your testing/debug/playing/developing code using and allowing VS to compile the code.
however, when you deploy (or edit "live"), then VS is NOT doing the code compile anymore. And this ALSO means then that the web site has both aspx pages, and ALSO the source code pages MUST ALSO exist!!! But often the web site and version of IIS will for example not know about Rosyln extensions etc., so you HAVE to be VERY careful, since it not VS that compiles the code, it is IIS that does this!!
In fact EVEN with a web site application, the "app_code" can and will be compiled by IIS. (I had simple code break when IIS re-compiles that code - it was not aware of say free form text strings that Rosylin allows). So, for a web site application, I actually create my own folder called MyCode and for each code module/class inside, then I right click and choose "compile" for the build options. That way IIS NEVER gets to compile my code!!!).
Now, of course the other option is what we call a "asp.net web application".
In that case, when you publish, then the code is compiled for you, the code behind pages is stripped out, and only the aspx pages remain (and are copied/deployed) to the web site. While this is more "pain" since even a tiny one-line change of code requires a WHOLE web site re-compile and re-deploy.
However, while there is this "increased" pain, there are also significant advantages.
You can have multiple projects in the one project.
you can add and reference other projects assemblies - not have to move/copy the assembles into the bin folder.
So, with better skills, then of course you often build code libraries and systems - systems that ALSO the web site requires. So, a asp.net "web site application" is a far better choice (compared to the "asp.net web site").
So, coming from a traditional software background, then hands down, I prefer the ability to have multiple projects in the one and same web project. And hands down I prefer the runtime compiling and management of external libraries of code and references being managed by the vs as opposed to "hoping" you setup and managed references correctly with a web site.
So, even those starting out say with PHP, or many other systems? Yes, they run a web server all the time, and then go edit the source files - and a simple "save" of the file you just edited means then a browser refresh, and you are done.
however, you lose a lot of control over referenced libraries, and KNOWING the build + compile is the same one you be running on the web site after a publish.
And note that a web site publish in effect will be just the SAME copy of the existing web site and files - there not really a "compile" process for publishing, and hence no "debug" folder really exists. It also means that each page launched on the site can out of the blue cause code to compile.
(Whereas with a asp.net web site application, there is a small startup delay the first time - probably due to JIT's running, but other than that, each additional pages and parts of the web site will not then have significant delays. With a web site re-publish, then huge delays can occur (but then again, often you never really have to re-publish do you - you are editing the live files!!). But, if you are working on a test copy, then yes, you are going to re-publish everything (actually copy the files - since nothing more is required). And as such then the web server really will be slow to start up, and slow to open pages that have not yet triggered compile of the code-behind pages (and you get a gazillion little .dll's as a result).
So, the only real issue here?
MAKE SURE you open the web site using file->open web site as opposed to file->open project. In theory and practice, such "web sites" thus don't have a .sln and project file. (it really is just a folder of files). As noted, many love this setup, especially for larger sites, since then little changes here and there are very easy. However, from an overall software management point of view, using git and source code, and things like writing unit test code, shared libraries, using multiple projects in one vs project file? You give up most of this with the web site option. So, yes, that setup is quick and dirty, but it not all that great if you more formalized in your software development approach.
I prefer strong references, and strong typing during the development process. I also prefer having VS manage my references. So, these abilities are worth more than a simple ctrl-s to update some code. However, if some bug crops up, while it can often be fixed by a simple edit of some code file and ctrl-s, and you are done? it will be harder to track down and find that bug in the first place!!!
To be fair, once a code project is created, then changes and fixes are often rather small - and this again actually favors that simple edit and ctrl-s deployment model.
it can often be painful to have to do a full re-publish of a whole big web application for JUST one little, tiny change of code, or even markup. And in most cases, when I deploy, I stop the web server services, publish, and then re-start the IIS web services.
So, it can "often" be hard to make a case that this deployment model (well, it doesn't really have a deployment model!!!) is bad, since it oh so easy to update bits and parts of an existing running site.
However, in the long run, I really can't endorse this way of development. I MUCH prefer using a web application. It is more git friendly, it allows things like testing code (unit testing), far better use of external class and library code, and you have a MUCH better control of compile and build of your code. Letting IIS compile the code base has increased risk, since you can't be sure during development that your final code and project will run the same when you deploy. (or least be far surer!).
It would be a history lesson.
More than two decades when Microsoft designed ASP.NET 1.0, the developers were using classic ASP which is simply Visual Basic code running on IIS. Thus, ASP.NET 1.0 has the mode of "ASP.NET Web Site" (used by your current employer) that you put source code on IIS and compile on the fly to mimic classic ASP.
It was after a few more years that Microsoft realized how bad that mode is, and introduced "ASP.NET Web Application" mode (used by your previous employer).
Microsoft has urged "ASP.NET Web Site" projects to be migrated to "ASP.NET Web Application" (or simply ASP.NET Core) for more than a decade, but unless IIS stops supporting those projects, many will not migrate at all.
"Is it okay" is impossible to be answered. Your current employer seems to enjoy that very well.
Reference
https://en.wikipedia.org/wiki/ASP.NET_Web_Forms
Say you have a large Web site, containing several discrete applications that run in the same site to do various things. You don't want to manage everything as a single project, so you break them apart, work on them in total isolation from one another, and just deploy them separately into the same runtime environment.
These applications will run in the same process. No virtual directories or app isolation. They will share things like session, cache, cookies, etc.
Sure, the code-behinds and class-libraries are just DLLs in the bin folder, but what of the presentation-level stuff that has to integrate in the runtime environment? What about sharing of the code-level resources I mentioned above -- cookies, session, cache, etc.? What about base page classes?
Example: it strikes me that every sub-app needs to be "master page aware" -- it needs to know where the master page will be located, and what ContentPlaceHolders are available, because the sub-apps Web forms will need to reference this stuff.
Any other thoughts here? Assume the sub-apps will share the same master page, theme, and everything else in the presentation layer, so they appear to be a seamlessly integrated part of the whole. But they will be worked on in different Visual Studio projects, by different dev teams that know nothing about one another except what's absolutely necessary.
Anyone want to share some best practices here?
You don't want to manage everything as a single project, so you break them apart, work on them in total isolation from one another, and just deploy them separately into the same runtime environment.
Why work in isolation? Establish a repository for the entire solution including all projects. Whatever change is made it is immediately available to all developers. With your approach it will be a nightmare to come.
Consider splitting responsibility by pages. One team does one segment, the other does the other one.
Another option is to let each team develop their part as a user control. You can easily assemble those together to represent a complete product.
I've been working on a legacy ASP.NET Web Site (versus a Web Application) project at a client for some time now, and its slow compile time has me wondering:
Are web site projects known to be slow(er) at compiling (than Web Application projects)?
It's a pretty small website, but the entire solution has tons of functionality -- 19 projects worth of it, 18 of which compile really quickly (the non-web projects). The website project itself has ~100 pages and ~15 user controls (these actually take about half of the compile time) and normally compiles within 30 to 60 seconds. A complete re-build takes closer to the latter.
So, some things I believe could be slowing it down (you debunk them):
(X)HTML validation issues (the code we inherited has thousands of compiler warnings about validation issues).
High levels of abstraction -- since the code for the website pages is compiled at run-time, I'm guessing that whatever it's doing for user controls up-front is a lengthy process so that the binding at compile-time can happen.
The mere size of the web site? I know these are not very efficient projects, and believe me, I've spent hours trying to get it converted to a web application, but Visual Studio was unable to parse a single ASPX file into its .aspx/.designer.xx components because of the validation problems I mentioned earlier.
Assuming my client won't approve more than a few hours to fix this up, is there any quick fixes, changes, or optimizations known that could help me out?
I do not have a puny computer, so its processing power is not an issue. I've also worked on Web Application projects equivalent in size and complexity that compile in just a few seconds.
I'm open to pretty much anything, so I'd love to hear your thoughts! Also, if you think this should be a wiki, let me know.
My observations have been the same: web site projects take awhile to build, longer then web app projects. I think I found some information on why, check this out: http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx
Search for "Iterative development". It says this about web site projects, when compared to web application projects:
By default, Visual Studio completely
compiles Web site projects whenever
you run or debug any page. This is
done to identify compile-time errors
anywhere in the site. However, a
complete site build can significantly
slow down the iterative development
process, so it is generally
recommended that you change the build
project option to compile only the
current page on run or debug.
First read this blog post Tips to optimize design-time build performance for Web Sites in Visual Studio 2005
Main points made:
Do not disable batch compilation
Leverage Server-side Compilation
Move App_Code files into a separate class library project
Check for conflicting dependencies
Turn off AutoToolboxPopulate in the Windows Forms Designer options.
Disable validation for HTML editing
Another option that could help you is switching to a RAM disk: Running development from a RAM disk – options and products
If that doesn't help maybe splitting your large WAP into multiple ones could improve compile time. Unfortunatelly that strategy requires you to drop developing on Cassini. Instead you will have to use IIS as host: Using multiple Web Application Projects (WAP) in one Solution
One fact most developers overlook in an ASP.NET Web Project is the amount of classes in the App_Code folder.
The more classes you put in it, the longer it will be the compilation time.
From the ASP.NET Compilation Overview on MSDN:
ASP.NET creates an assembly for each
application directory (such as
App_Code) and one for the main
directory. (If files in a directory
are in different programming
languages, then separate assemblies
will be created for each language.)
So, if you can basically minimize the Folder Hierarchy and reduce the amount of classes in it, it will probably reduce the compilation time.
Another thing I noticed from your post is that, you have 18 non-website projects.
I think it is a bit too excessive because think of it this way.
When the Web Project compilation starts, the ASP.NET Compiler needs to link the 18 separate DLL files.
If those projects can be combined to reduce the number of DLLs, it might help also.
From maintainability viewpoint, having 18 projects is a bit excessive unless there are REAL strong reasons to do so.
I would suggest reviewing the projects and combine them.
I hope it helps.
This may not be ideal, but you can split your projects into multiple solutions. For example you can take the user controls and put them in Solution A and the rest of projects into Solution B. Then compile the controls in Solution A and file reference to them from Solution B which should help cut down the compile time
Website or web project, the performance should be similar after compilation phase. If the issue is poor performance immediately after deploying a new set of codes, a quick way I can think of is to pre-publish the site. (see reference http://msdn.microsoft.com/en-us/library/1y1404zt(VS.80).aspx)
Depending on the options you choose during the publishing, you may lack flexibility to make changes on the fly (which you shouldn't anyway).
I have looked through the related questions, and none of them have provided me the information I am looking for.
Currently the team I work on does deployments of individual .aspx (and .aspx.vb) files for bug fixes/enhancments. I am trying to affect change, as I really believe that deploying the "whole compiled site" is less error prone. As this is a significant change from the way things have been done, my suggestions have ben met with significant resistance.
As my google-fu has not been up to par lately, I was hoping the SO community could either tell me that I am off my rocker, and that there is nothing wrong with moving individual files, or point me to some really good resources which would allow me to make a stronger case.
Edit:
This has all been great info, and reinforces the arguments that I have already been making, can anyone argue the other side?
Deploying individual files for bug fixes and deployment is not a wise strategy. It sounds like you need a comprehensive build and deployment process. That doesn't mean it has to be complicated as there are some good tools available nowadays.
Build and deployment can get detailed, so as a minimum start try taking a look at the Microsoft Web Deployment Tool (http://www.iis.net/extensions/WebDeploymentTool). Install the tool on your build server and install it on your deployment server. Stage your ASP.NET content locally using the Visual Studio Publish command, then use the above tool to synchronize the entire package on the deployment server. I like this approach because it can be completely automated. When doing builds and deployments, aim for complete automation to reduce potential errors.
This is the bare minimum, but you will at least be certain that when specific files are changed, they are ALL synchronized on the deployment server.
Personally to me rolling back immediately is most important. Again website projects are very hard when it comes to track the changes.
you can find a good detailed comparison here. I am reproducing the article here.
1) Deployment. If you need in-place deployment, this model is perfect. However, it's not recommended since you are exposing your logic in clear text. So, anybody who have access to physical server can mess with your code and you never going to notice this. You can try to make precompiled web site, but you going to end up with a lot of dll and almost untouchable aspx files. Microsoft recognized this limitation and released Web Deployment Project tool.
2) You need to keep track of what did you change locally and what did you upload to production server. There are no versioning control. Visual Studio has Web Copy tool, but this tool fails to help. I had to build my own tool, which kept track of changes based on Visual Source Safe.
3) When you hit F5 for debug execution it takes merely 2 minutes to compile and execute whole project. Of course you can attach debugger to existing thread, but this is not an obvious solution.
4) If you ever try to generate controls on a fly you will hit first unsolvable limitation. How to reference other pages and controls. Page and control compilation happens on a per directory basis. On best case you going to get assembly for each directory, in worst each page or control is going to get its own assembly. If you need to reference another page from a control or another page you need to explicitly import it with the #Reference directive.
So for,
customControl = this.LoadControl("~/Controls/CustomUserControl.ascx") as CustomUserControl;
You need,
But what if you want to add something really dynamically and can't put all appropriate #Reference directives? Or What if you are creating server control and it doesn't have ascx file, so you don't have a place for #Reference ? Since each control has it's own assembly, it's almost impossible to do reflection.
Web Application Projects which re-appeared in Visual Studio 2005 SP1. They solves all issues mentioned above.
1) Deployment. You get just one dll per project. You can created redistributable packages and repeatable builds.You can have versioning and build scripts.
2) If you did code behind change you can upload just one dll. If you did aspx change you can upload just aspx change.
3) Execution takes 2-3 sec maximum.
4) Whole project is in one assembly, which helps reference any page or control. Conclusion. For any kind of serious work you should use Web Application Projects. Special thanks to Rick Strahl for his amazing article Compilation and Deployment in ASP.NET 2.0.
I agree with Rich.
Further information:
Deploying your SOURCE code ala the .vb files to the server is a BAD idea. Compile it. Obfuscate if you can, just don't deploy straight source. Imagine an attacker which gains access to the system. They could easily change your code and you might not ever notice. Yes, you can use a tool like reflector to decompile. But it's really hard to decompile a full site, make the changes you want, and put them back into production.
Deploying a single file might very well cause some type of problem in a related module. I'm guessing you guys don't really do QA. Tell them it's time to grow up.
Compiling your site will reduce JIT (just in time) compilation. Think performance.
I'm also going to guess that pretty much everyone has production server access. This is bad from the company's perspective as you have no controls in place. What happens when an employee decides to cause some havoc before leaving?
What you are describing is inline with Cowboy coding. Sure, it's fun to ride to the rescue but this style frequently blows everything up.
It's bad for rolling back. If you deploy as a web site vs web app, yeah you can do quick patches of one or two files, but what if you ever need to roll back to a previous version? Good luck tracking down all the files that were updated to make the new version. I much prefer the concept of a "version" for organizational reasons, and the compiled web app is much more inline with this than a "website" project.
We had this dilemma and ended up going with the compiled version mainly for the security reasons. If your site is external facing you could be compromising your security by allowing the vb files to be out there in plain text. I realize one could still get your code if they really wanted to but it would be an additional hurdle they would need to go through. If you use Visual Studio as your development environment you can publish the site pre-compiled and check the named assemblies option when publishing and this will essentially create a dll for each aspx page so you can do the one off page changes if necessary. This was a great feature we found as we were constantly updating the whole site and there were times when things would get updated that shouldn't. After using that feature we no longer had updates getting pushed that shouldn't. As far as rolling back I hope your using some type of Source control / versioning system. Team Foundation Server is great for versioning/source control but it is quite pricey.
What is the best deployment strategy depends a lot on what kind of environment you are working in, and what kind of developers you are working with.
Visual artists that started with graphic layout and worked towards programming are much more in tune to individual page generation and release. Also the .aspx.vb files are simply server side scripting, not really programming.
Programmers usually start at the command line and branch out to environments such as the web and understandably feel that good programming practices should be applied too the web, including standard test and release cycles (and compiled code).
If the site is in constant flux the individual pages would make more sense, but if you are required to deliver an installation package to your production group msi files are the way to go, since they can be easily backed out if necessary.
If you evaluate what your groups needs are, which includes the varied experience of everyone in your group, you should be able to convince either yourself or the group. This is not a matter of which is better, but which provides the best business model.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
ASP.NET: Web Site or Web Application?
I have noticed that there is clearly a difference in what you get when you fire up Visual Studio 2008 and choose 'New Project' -> 'ASP.NET Web Application' instead of 'New Web Site' -> 'ASP.NET Web Site'. For example if you choose 'Project', then you can compile to .dll and each page gets a *.aspx.designer.cs codebehind file.
1) Why do we have these two different project types?
2) Which do you prefer?
3) Why would I choose one over the other?
4) What's the deal with the *.aspx.designer.cs files?
They have different purposes.
A website is a site with content that is likely to change over time, that is the pages themselves will change. There is no actual project file and the site is deployed simply as a set of files.
An application is a site where the content is just the application, the dynamic part will mainly be in persistant store such as a database. It will have more complex logic since its likely to represent a set of forms for data entry as much as a means to examine content. It has a project file to more strictly control its configuration and its code deployed as a compiled dll.
1) The 'web site' model was introduced with ASP.NET 2.0, the 'web application' model was the project type of the original .net framework. They both have different uses (see below).
2) It depends on the context. A good example is if you are selling a software product, you may wish to use a 'web application' project because it naturally lends itself to cleanly compiled code.
3) See above, personal preference, maintenance characteristics. An interesting thing that a 'web site' allows you to do that can get you in a lot of trouble is making arbitrary changes to code-behind (typically a *.cs or *.vb) file in notepad while the website is running.
4) The designer.cs file is used to store the auto-generated code. "This code was generated by a tool."
MSDN Article describing the differences
Similar stackoverflow question
I won't duplicate the definition of the 2, since that just got answered.
So why use one over the other?
Web Site lets you treat it like a PHP or classic ASP site, where you can make inline changes that take effect immediately.
Pros
You can make tweaks to the site right on the web server
Deploying is as simple as copying the folder
Cons
If you are not making the changes right on the live site, you can get into change management problems, where you forget to keep all your files in sync
You can get runtime syntax errors displayed to your end users, since the only way to check is to manually run every page
Web Application lets you treat it more like how you would a desktop application - there is one deployable that is compiled on your machine.
Pros
Clear, structured change management. You cannot accidently mix code from two different versions. This can be important when there are 2 people involved - one writing the code, and one responsible for putting files on the server.
Because you compile it on your machine, everything gets syntax checked at that point*
Cons
Deployment is a little more involved then just copying the folder from your development machine. However the usage of the "Publish" command greatly simplifies the process of compiling and putting together what files should be copied to the web server.
Any changes need to be done on your machine, compiled, and a whole new version sent to the web server*
*The aspx/html files are only syntax checked if you turn this on in your build options though. It is also possible to edit these files on the server unless they are compiled into your project.
The simple answers are as follows:
New Web Site - creates code behind pages that are compiled at the server when page is requested.
New Web Project - creates pre-compiled pages into one or more assemblies (entire site even), and deployed on server.
Scenario #1 - If a hacker obtains your code-behind files, any database passwords are exposed. These pages are compiled at the time they are requested. You can choose to pre-compile everything into a large assembly. If not, there is more load on the server.
Scenario #2 - if a hacker obtains your assemblies, they will be obfuscated. Obfuscated assemblies are harder to crack. These assemblies are pre-compiled, thus reducing load on the server.
For more information:
Introduction to Web Application Projects
3) WebApplication projects are buildable by MSBuild. WebSites are not (without a lot of tweaking). If you use TeamSystem with automated builds then this is the way to go.
THe biggest difference that no one has really mentioned (except touched on by Annakata) is that with the model where everything is compiled into a single DLL, your have complete control over the classes that your application generates. You know where they are and can always reference them from anywhere else in the application.
With the single page model, you can't do this. You have to get around it by creating "stub" classes in the AppCode directory, and inheriting those in your pages, but even that isn't ideal, and add complexity.
You'll only really come up agaist this stuff if you're trying to develop an intricate dynamic site, where you dynamically load lots of user-controls at run-time based on content. Then, the differences are painfully clear - hence much of our development stalled on ASP 1.1 until we could go back to the same model later.
Nich
Speaking from experience with both: "Web Sites" are used where there is no testing methodology in place, no CI server, and a culture that encourages and promotes "hotfixes" to specific pages regularly. "Web Applications" are the de facto standard where proper software methodologies are followed and there is unit testing (if not full TDD) and a CI server with a focus on writing clean code and finding bugs before the need for a "hotfix" arises.
Sites are the 2003 original .NET way of doing web dev. In my experience they are extremely problematic since lacking a project definition they can't be reused and have issues with modular coding, have issues with TeamSystem integration and namespacing. The one-to-one bind with a domain and lack of real publishing abstraction creates maintenance problems down the line.
The ancient "classic" ASP way of !codebehind is a serious problem because it again impairs code reuse and testing, and the often cited benefits of allowing hot fixes - if ever called upon - is actually a massive signal that you have a failing development process. The ability to hot fix is of course better than not being able to, but it's something you never want to invoke.
You might say that the problems with the web site model were great enough that MS gave us web apps instead. Personally I would never use them for anything beyond demo code... no actually I wouldn't even do that.
At first there was a Web application project (it behaved similarly to the current Web site project). They changed it to reflect what some users requested. However people wanted the old functionality back so they re-introduced the Web site project which behaves like the original Web application project.
I -- and my workplace -- prefer the Web site project
We like that the files of the website are the files in the file system (no need to add them manually)
No idea
Here's two articles I found about both:
http://damieng.com/blog/2008/02/07/web-site-vs-web-application
http://www.dotnetspider.com/resources/1520-Difference-between-web-site-web-application.aspx
Note: A lot of the issues with Web sites have been resolved with the Web deployment project
Update: Fixed the point 1, Web application was there first
If your work needs to leverage oo language features (class hierarchies, namespaces) or if you need to reuse common code among projects (data access, class libs etc.) then the web application project is the only way to go.
The website project (the clue is in the name) is only really good for non-complex 'brochureware' sites (where the pages consist of static content) as opposed to web applications.
There is very little difference, and I would highly recommend using the Web Site model.
The main difference is for a website, some files need to be placed in certain directories (code files need to be placed in the 'App_Code' directory), besides that, it's pretty straight forward.
If having compiled code for deployment is important to you, and you want a single DLL (opposed to the several that are created when you do a normal publish for a web site), then you'll want to get this add-on: http://msdn.microsoft.com/en-us/asp.net/aa336619.aspx