ASP.NET Web Site or ASP.NET Web Application?

2018-12-31 01:40发布

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

What is the difference between ASP.NET Web Application and ASP.NET Web Site? Why would I choose one over other?

Is the answer different based on which version of Visual Studio I am using?

25条回答
大哥的爱人
2楼-- · 2018-12-31 02:18

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 the code yet. Another problem can be in publishing.

If Visual Studio 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 DLL files containing the same class name, which will generate plenty of errors. The Web Site project was introduced with Visual Studio 2005, but it 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 Visual Studio 2005. The main differences are the Web Application Project was designed to work similar to the Web projects that shipped with Visual Studio 2003. It will compile the application into a single DLL file at build time. In order to update the project, it must be recompiled and the DLL file published for changes to occur.

Another nice feature of the Web Application project is it's much easier to exclude files from the project view. In the Web Site project, each file that you exclude is renamed with an excluded 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 tidier.

Reference

The article ASP.NET 2.0 - Web Site vs Web Application project 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.

Web Application Projects versus Web Site Projects (MSDN) explains the differences between the web site and web application projects. Also, it discusses the configuration to be made in Visual Studio.

查看更多
看风景的人
3楼-- · 2018-12-31 02:18

In Web Application Projects, Visual Studio needs additional .designer files for pages and user controls. Web Site Projects do not require this overhead. The markup itself is interpreted as the design.

查看更多
梦醉为红颜
4楼-- · 2018-12-31 02:20

From the MCTS self paced training kit exam 70-515 book:

With web application (project),

  1. You can create an MVC application.
  2. Visual Studio stores the list of files in a project file (.csproj or .vbproj), rather than relying on the folder structure.
  3. You cannot mix Visual Basic and C#.
  4. You cannot edit code without stopping a debugging session.
  5. You can establish dependencies between multiple web projects.
  6. You must compile the application before deployment, which prevents you from testing a page if another page will not compile.
  7. You do not have to store the source code on the server.
  8. You can control the assembly name and version.
  9. You cannot edit individual files after deployment without recompiling.
查看更多
明月照影归
5楼-- · 2018-12-31 02:20

One of the key differences is that Websites compile dynamically and create on-the-fly assemblies. Web applicaitons compile into one large assembly.

The distinction between the two has been done away with in Visual Studio 2008.

查看更多
梦醉为红颜
6楼-- · 2018-12-31 02:22

Website and Project>>website are two different methods of creating ASP.NET application using visual studio. One is projectless and another is project environment. Differences are as

  1. Solution file is stored in same directory as root directory in project environment.
  2. Need to remove solution and project files before deploying in project environment.
  3. Complete root directory is deployed in projectless environment.

there no much basic difference in using either approach. But if you are creating website that will take longer time, opt for project environment.

查看更多
姐姐魅力值爆表
7楼-- · 2018-12-31 02:24

WebSite : It generates app_code folder automatically and if you publish it on the server and after that if you do some changes in any particular file or page than you don't have to do compile all files.

Web Application It generates solutions file automatically which website doesn't generate and if you change in one file than you have to compile full project to reflects its changes.

查看更多
登录 后发表回答