Difference between 'Web Site' and 'Project' in Visual Studio

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?


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

  • 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.


    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.

    链接地址: http://www.djcxy.com/p/95918.html

    上一篇: ASP.NET VS 2010:网站或Web应用程序?

    下一篇: Visual Studio中“网站”和“项目”之间的区别