views:

7188

answers:

14

When I start a new ASP.NET project in Visual Studio 2008, I can either create a new ASP.NET Web Site or an ASP.NET Web Application.

What's the difference between these two project types? Why would I choose one over the other?

If I'm using Visual Studio 2005 instead of Visual Studio 2008, is the answer different?

If I'm using Visual Studio 2010, is the answer different?

+4  A: 

Web sites are dynamically compiled and source is distributed with them. Web Applications can be compiled into a single DLL and deployed.

You cannot use the app_code folder in WAP projects, but you can with WSP.

There is a bit of MSDN documentation between WAP/WSP.

Mitchel Sellers
+119  A: 

Website:

The Web Site project is compiled on the fly. You end up with a lot more DLL files, which can be a pain. It also gives problems when you have pages or controls in one directory that need to reference pages and controls in another directory since the other directory may not be compiled into code yet. Another problem can be in publishing.

If VS isn't told to re-use the same names constantly, it will come up with new names for the dll files generated by pages all the time. That can lead to having several close copies of dlls containing the same class name, which will generate plenty of errors. The Web Site project was introduced with VS 2005, but has turned out not to be extremely popular.

Web Application:

The Web Application Project was created as an add-in and now exists as part of SP 1 for VS 2005. The main differences are the Web Application Project was designed to work similar to the Web projects that shipped with VS.net and VS 2003. It will compile the application into a single dll at build time. In order to update the project it must be recompiled and the dll published for changes to occur.

Another nice feature of the Web Application project is it's much easer to exclude files from the project view. In the Web Site project, each file that you exclude is renamed with an exclude keyword in the filename. In the Web Application Project, the project just keeps track of which files to include/exclude from the project view without renaming them, making things much tider.

Reference: http://www.megasolutions.net/AspNet/difference-between-Web-Site-and-Web-Application-Project-27210.aspx

This article also gives reasons on why to use one and not the other. Here is an excerpt of it:

  • You need to migrate large Visual Studio .NET 2003 applications to VS 2005? use the Web Application project.
  • You want to open and edit any directory as a Web project without creating a project file? use Web Site project.
  • You need to add pre-build and post-build steps during compilation? use Web Application project.
  • You need to build a Web application using multiple Web projects? use Web Application project.
  • You want to generate one assembly for each page? use Web Site project.
  • You prefer dynamic compilation and working on pages without building entire site on each page view? use Web Site project.
  • You prefer single-page code model to code-behind model? use Web Site project.
Andreas Grech
Thanks Dreas. I hope this question/answer combo bubbles to the top of the Google search results.
Robert S.
You can still compile your entire site into a dll with the file based Web Site.
metanaito
The way I tend to think of it. If you are programming an application that happens to use HTML as it UI then use Web Application. If you have a web site that happens to need a bit of Asp.net on a few of its pages use Web Site Project.
Ian Ringrose
Actually, Web Application Projects were precisely the original ASP.NET project type. They are not "like" the projects we had in Visual Studio 2003. They were not created as an add-in. Visual Studio 2005 SP1 simply restored what Visual Studio 2005 RTM mistakenly removed.
John Saunders
You can use WebApplication output in a WebDeployment project. You cannot use WebSite output in a WebDeployment project. If you want to create a Deployment project, stick to WebApplication. But for developing, WebSite is more convenient. However, conversion is not always problemlesss, so start with WebApplication right away.
Quandary
+3  A: 

This may sound a bit obvious, but I think it's something that is misunderstood because VS2005 only shipped with the web site originally. If your project deals with a website that is fairly limited and doesn't have a lot of logical or physical separation, the website is fine. However if it is truly a web application with different modules where many users add and update data, you are better off with the web application.

The biggest pro of the website model is that anything in the app_code section is dynamically compiled. You can make cs file updates without a full redeploy. However this comes at a great sacrifice. A lot of things happen under the covers that are difficult to control. Namespaces are difficult to control and specific dll usage goes out the window by default for anything under app_code since everything is dynamically compiled.

The web application model does not have dynamic compilation, but you gain control over the things that I have mentioned.

If you are doing nTier development, I highly recommend the web application model. If you are doing a limited web site or a quick and dirty implementation, the web site model may have advantages.

More detailed analysis can be found here:
http://west-wind.com/weblog/posts/5601.aspx
http://blogs.vertigo.com/personal/swarren/Blog/Lists/Posts/Post.aspx?ID=10

Daniel Auger
>The biggest pro of the website model is that anything in the app_code section is dynamically compiled. This has a big downside as well. My web site is hosted with webhost4life who are cheap but feature rich. The downside is that they recycle the worker process very frequently (15 mins?) which means that the next user has a very slow first-page-out as the application is re-compiled.
Rob Nicholson
+8  A: 

Here is a post I put out that may answer your question:

http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx

In short, stick to the Web Application project if you're doing any serious work.

Anthony :-)

IrishChieftain
@IrishChieftain, here on SO answers containing only links are frowned upon. You should provide an excerpt of salient points from the link.
Robert S.
Thanks for the heads-up :-)
IrishChieftain
So you ignored my advice. :(
Robert S.
Sorry God... I didn't realize I had to go to confession :-O
IrishChieftain
That was quite rude.
Robert S.
Didn't mean to come across as rude. Frankly, the link I provided will give you all the info you required. I see no need to be reprimanded for not following your advice (read: doing the work for you!) to the letter.
IrishChieftain
+1 for your link/post. I like links and never frown upon them. That's called the "IntarWeb", isn't it?
splattne
Aha... a fellow savant! Seriously, I get pissed just like a kid when someone votes me down :-S
IrishChieftain
I didn't vote you down, as the link is good, but there's an accepted way of doing things here. There's a SOFAQ post that explains the blog-linking policy. I'll see if I can find it.
Robert S.
Thanks Out Into Space :-) As far as an policy goes, I think if the link answers the question, then what more can one ask for?
IrishChieftain
He asked for an excerpt of salient points from the link.
Homer
+2  A: 

Web Site = use when the website is created by graphic designers and the programmers only edits 1 or 2 pages

Web Application = use when the application is created by programmers and the graphic designers only edit 1 or two paged/images.

Web Sites can be worked on using any HTML tools without having to have developer studio, as project files don’t need to be updated etc. Web Applications are best when the team is mostly using developer studio and there is a high code content.

Ian Ringrose
+23  A: 

I seriously do not understand the benefits of Web application projects.

  • Building everything into one assembly means you have to re-build for every little change, and you cannot make live changes. This can be a real pain during development, since you have to keep re-building to see the changes, while with Websites changes are detected by the runtime and pages/controls are automatically recompiled.

  • Web application projects do not support custom build providers, so you cannot use other languages like php, ruby, python or whatever language you invented (http://msdn.microsoft.com/en-us/library/system.web.compilation.buildprovider.aspx).

"You end up with a lot more DLL files, which can be a pain"

  • Actually, you don't manage those DLL's, they are placed in %windir%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\, you don't even have to know they exists. Not an issue.

  • Having the runtime manage the assemblies is actually less work for you, since you don't need to worry about giving pages/controls unique names, or organizing them into different namespaces.

  • Dynamic compilation is also used with Web application projects, for things like Page and OutputCache directives, these are parsed by the .aspx build provider which generates a class that inherits from the pre-compiled webapp page class.

"It also gives problems when you have pages or controls in one directory that need to reference pages and controls in another directory since the other directory may not be compiled into code yet."

  • This is not a problem because the framework supports this scenario. In pages/controls, you use the Reference directive.

  • In Web application projects you don't get error detection in pages/controls as the compiler only compiles your codebehind classes and not the markup code.

  • In Websites every file and directory is part of the website that get's deployed, which is very transparent, you are working with THE website, not a project that WILL PRODUCE a website. In Web applications you need an additional 'Publish' step.

Websites and dynamic compilation are the core of ASP.NET, Web applications is just an abstraction used to fit the Visual Studio project paradigm. In the end what ASP.NET parses and executes are websites.

If you are into MVC or separation of concerns, putting your templates, images and css into the same project as your model, data-access, bussines logic, is wrong. On the other hand, if you want to put everything into one project web application is obviously better.

Max Toro
Because the programmers write the application, the application is then built. The test team tests the application on the test system. Then the customer installs the applications. That LAST think you want is anyone making live changes!
Ian Ringrose
I'm not saying making live changes is good or bad, just that webapp projects doesn't support them.
Max Toro
Which is a *good* thing IMHO. It makes a mockery of any code, test, release process which has to be the bedrock of any serious application
Rob Nicholson
To me having the choice is the best, on websites you can always inherit from a pre-compiled base class if you want to. There are many languages/frameworks (e.g. PHP) where people are used to the idea of deploying source code. That doesn't mean those are not 'serious' applications.
Max Toro
+1 for having the stones to go against general "accepted" opinion
roosteronacid
"Actually, you don't manage those DLL's, [...] you don't even have to know they exists. Not an issue." - Until the framework gets confused, doesn't clean the old versions up correctly, and starts throwing compilation exceptions with conflicting names all over the site... You can add error detection of the markup through the use of a WebDeployment project. I'm also not sure on your last point "with websites you can use IIS as the server", you can do this with a Web Application as well - and I have projects like this where the project is part of a larger web application.
Zhaph - Ben Duguid
A: 

Some details from Apress – Pro ASP.NET 3.5 in C# 2008 Second Edition

Websites and Web Projects

Amr ElGarhy
+2  A: 

One thing to watch out for is that Website projects are difficult to build with MSBuild. You will only come up against this is if you are planning to automate the build which has always worked extremely well for me.

Burt
+1  A: 

One additional benefit of the Web Application is that it produces a DLL suitable for static analysis. Trying to use tools like NDepend on a Web Site project is not fun.

Larsenal
+5  A: 

Unless you have a specific need for a dynamically compiled project, don't use a web site project.

Why? Because web site project will drive you up the wall when trying to change or understand your project. The static typing find features (e.g. find usages, refactor) in VS will all take forever on any reasonably size project. For further information, see the the SO question: Slow “Find All References” in Visual Studio

I really can't see why they dropped web applications in VS2005 for the pain-inducing, sanity-draining, productivity carbuncle web site project type.

ninj
A: 

Continuous integration was much simpler for me when using Web Application projects. I've tried both, and the website required jumping through some hoops with Cruise Control.Net.

Brandon Joyce
+10  A: 

Chek out the article I wrote dedicated to the differences between Web Application Projects vs Web Site Projects at http://vishaljoshi.blogspot.com/2009/08/web-application-project-vs-web-site.html -Vishal

Vishal R. Joshi
Welcome, Vishal! This great post will now be my answer to anyone who asks about the difference.
John Saunders
Ditto. Excellent article, Vishal.
Josh Kodroff
A: 

This is an old question but in case anybody is reading and wants to know the difference, I recommend you watch this video on asp.net website which explains the difference in great detail, it was quite helpful to me.

Web Application Projects & Web Deployment Projects

By the way, don't get confused by the title, a great part of the video explains the difference between website projects and web application projects and why Microsoft re-introduced Web application projects in Visual studio 2005 (as you probably already know, it originally shipped with only website projects then web application projects were added in SP1). A great video I highly recommend for anyone who wants to know the difference.

Waleed Eissa
A: 

I have an interesting scenario: - Site has 209,000+ pages. - Evertime a user submits a new article/item a new page is generated and if it has a refernece to one of the existing pages then that page is also re-generated and saved. - A windows service is looking after the generation of pages which creates a page(file) in the site directory. - The purpose of pre-generated pages was to save requesting data from the database as 75% times data will never be updated and having a pre-generated file on the FS saves processing and memory.

It has been working very well but we are concerned now...

The problem is the disk space is running out and if we restart the server it takes a while for site to compile and run and as volume increases we think this will cause us serious problems.

Is there a way to have pre-compiled site and we can still generate pages? (the generated pages all inherit from one class and they have custom controls)

Any suggestions?

Usman Akram
You should ask this as a separate question, not as an answer to a question asked 9 months ago. It isn't likely to get much attention here. Click the "Ask Question" button at the top right of the page. You can add a link to this question if you think it will help.
Bill the Lizard