ASP.NET网站或ASP.NET Web应用程序?

时间:2021-01-12 03:17:28

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.

当我在Visual Studio中启动一个新的ASP.NET项目时,我可以创建一个ASP.NET Web应用程序,或者我可以创建一个ASP.NET Web站点。

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

ASP.NET Web应用程序和ASP.NET Web站点之间有什么区别?为什么我会选择一个而不是其他?

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

根据我使用的Visual Studio版本,答案是否有所不同?

25 个解决方案

#1


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.

Web站点项目即时编译。你最终得到了更多的DLL文件,这可能是一个痛苦。当您在一个目录中有页面或控件需要引用另一个目录中的页面和控件时,它也会出现问题,因为其他目录可能尚未编译到代码中。另一个问题可能是出版。

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.

如果没有告诉Visual Studio不断重复使用相同的名称,它将为页面始终生成的DLL文件提供新名称。这可能会导致包含相同类名的DLL文件的几个密切副本,这将产生大量错误。 Web站点项目是在Visual Studio 2005中引入的,但事实并非如此受欢迎。

Web Application:

The Web Application Project was created as an add-in and now exists as partof SP 1 for Visual Studio 2005. The main differences are the Web Application Projectwas 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 buildtime. In order to update the project, it must be recompiled and the DLL filepublished for changes to occur.

Web应用程序项目是作为加载项创建的,现在作为Visual Studio 2005的SP 1的一部分存在。主要区别在于Web应用程序项目的设计类似于Visual Studio 2003附带的Web项目。它将编译在构建时将应用程序应用到单个DLL文件中。为了更新项目,必须重新编译它,并发布DLL文件以进行更改。

Another nice feature of the Web Applicationproject is it's much easier to exclude files from the project view. In theWeb Site project, each file that you exclude is renamed with an excludedkeyword in the filename. In the Web Application Project, the project justkeeps track of which files to include/exclude from the project view withoutrenaming them, making things much tidier.

Web Applicationproject的另一个不错的功能是从项目视图中排除文件要容易得多。在“Web站点”项目中,您排除的每个文件都使用文件名中的excludedkeyword重命名。在Web应用程序项目中,项目只是跟踪从项目视图中包含/排除哪些文件而不重命名它们,使事情变得更加整洁。

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:

文章ASP.NET 2.0 - Web站点与Web应用程序项目也给出了为什么使用一个而不是另一个的原因。以下是它的摘录:

  • You need to migrate large Visual Studio .NET 2003 applications to VS 2005? use the Web Application project.
  • 您需要将大型Visual Studio .NET 2003应用程序迁移到VS 2005吗?使用Web应用程序项目。

  • You want to open and edit any directory as a Web project without creating a project file? use Web Site project.
  • 您想在不创建项目文件的情况下打开和编辑任何目录作为Web项目吗?使用网站项目。

  • You need to add pre-build and post-build steps during compilation? use Web Application project.
  • 您需要在编译期间添加预构建和后构建步骤吗?使用Web应用程序项目。

  • You need to build a Web application using multiple Web projects? use Web Application project.
  • 您需要使用多个Web项目构建Web应用程序吗?使用Web应用程序项目。

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

Web应用程序项目与Web站点项目(MSDN)解释了Web站点和Web应用程序项目之间的差异。此外,它还讨论了在Visual Studio中进行的配置。

#2


Web Site is what you deploy to an ASP.NET web server such as IIS. Just a bunch of files and folders. There’s nothing in a Web Site that ties you to Visual Studio (there’s no project file). Code-generation and compilation of web pages (such as .aspx, .ascx, .master) is done dynamically at runtime, and changes to these files are detected by the framework and automatically re-compiled. You can put code that you want to share between pages in the special App_Code folder, or you can pre-compile it and put the assembly in the Bin folder.

Web站点是您部署到ASP.NET Web服务器(如IIS)的内容。只是一堆文件和文件夹。网站中没有任何内容可以将您与Visual Studio联系起来(没有项目文件)。代码生成和网页编译(例如.aspx,.ascx,.master)在运行时动态完成,框架检测到这些文件的更改并自动重新编译。您可以在特殊的App_Code文件夹中放置要在页面之间共享的代码,也可以预编译它并将程序集放在Bin文件夹中。

Web Application is a special Visual Studio project. The main difference with Web Sites is that when you build the project all the code files are compiled into a single assembly, which is placed in the bin directory. You don’t deploy code files to the web server. Instead of having a special folder for shared code files you can put them anywhere, just like you would do in class library. Because Web Applications contains files that are not meant to be deployed, such as project and code files, there’s a Publish command in Visual Studio to output a Web Site to a specified location.

Web应用程序是一个特殊的Visual Studio项目。与Web站点的主要区别在于,在构建项目时,所有代码文件都编译为单个程序集,该程序集位于bin目录中。您不会将代码文件部署到Web服务器。您可以将它们放在任何位置,而不是像在类库中那样放置共享代码文件的特殊文件夹。由于Web应用程序包含不打算部署的文件(例如项目和代码文件),因此Visual Studio中有一个“发布”命令可将网站输出到指定位置。

App_Code vs Bin

Deploying shared code files is generally a bad idea, but that doesn’t mean you have to choose Web Application. You can have a Web Site that references a class library project that holds all the code for the Web Site. Web Applications is just a convenient way to do it.

部署共享代码文件通常是个坏主意,但这并不意味着您必须选择Web应用程序。您可以拥有一个引用类库项目的Web站点,该项目包含Web站点的所有代码。 Web应用程序只是一种方便的方法。

CodeBehind

This topic is specific to .aspx and .ascx files. This topic is decreasingly relevant in new application frameworks such as ASP.NET MVC and ASP.NET Web Pages which do not use codebehind files.

本主题特定于.aspx和.ascx文件。在不使用代码隐藏文件的ASP.NET MVC和ASP.NET Web页面等新应用程序框架中,此主题越来越相关。

By having all code files compiled into a single assembly, including codebehind files of .aspx pages and .ascx controls, in Web Applications 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 Web Sites changes are detected by the runtime and pages/controls are automatically recompiled.

通过将所有代码文件编译为单个程序集(包括.aspx页面和.ascx控件的代码隐藏文件),在Web应用程序中,您必须为每个小的更改重新构建,并且您无法进行实时更改。这在开发过程中可能是一个真正的痛苦,因为您必须不断重新构建以查看更改,而运行时检测到Web站点更改并自动重新编译页面/控件。

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

让运行时管理代码隐藏程序集对您来说不那么重要,因为您不必担心为页面/控件提供唯一名称,或者将它们组织到不同的名称空间中。

I’m not saying deploying code files is always a good idea (specially not in the case of shared code files), but codebehind files should only contain code that perform UI specific tasks, wire-up events handlers, etc. Your application should be layered so that important code always end up in the Bin folder. If that is the case then deploying codebehind files shouldn't be considered harmful.

我不是说部署代码文件总是一个好主意(特别是在共享代码文件的情况下),但代码隐藏文件应该只包含执行UI特定任务的代码,连接事件处理程序等。您的应用程序应该是分层,以便重要的代码总是在Bin文件夹中。如果是这种情况,那么部署代码隐藏文件不应被视为有害。

Another limitation of Web Applications is that you can only use the language of the project. In Web Sites you can have some pages in C#, some in VB, etc. No need for special Visual Studio support. That’s the beauty of the build provider extensibility.

Web应用程序的另一个限制是您只能使用项目的语言。在网站中,您可以在C#中创建一些页面,在VB中使用一些页面等。不需要特殊的Visual Studio支持。这就是构建提供程序可扩展性的美妙之处。

Also, in Web Applications you don't get error detection in pages/controls as the compiler only compiles your codebehind classes and not the markup code (in MVC you can fix this using the MvcBuildViews option), which is compiled at runtime.

此外,在Web应用程序中,您不会在页面/控件中获得错误检测,因为编译器只编译您的代码隐藏类而不是标记代码(在MVC中您可以使用MvcBuildViews选项修复此问题),这是在运行时编译的。

Visual Studio

Because Web Applications are Visual Studio projects you get some features not available in Web Sites. For instance, you can use build events to perform a variety of tasks, e.g. minify and/or combine Javascript files.

由于Web应用程序是Visual Studio项目,因此您将获得Web站点中不具备的一些功能。例如,您可以使用构建事件来执行各种任务,例如缩小和/或组合Javascript文件。

Another nice feature introduced in Visual Studio 2010 is Web.config transformation. This is also not available in Web Sites. Now works with Web Sites in VS 2013.

Visual Studio 2010中引入的另一个不错的功能是Web.config转换。这在网站中也不可用。现在可以在VS 2013中使用网站。

Building a Web Application is faster than building a Web Site, specially for large sites. This is mainly because Web Applications do not compile the markup code. In MVC if you set MvcBuildViews to true then it compiles the markup code and you get error detection, which is very useful. The down side is that every time you build the solution it builds the complete site, which can be slow and inefficient, specially if you are not editing the site. l find myself turning MvcBuildViews on and off (which requires a project unload). On the other hand, with Web Sites you can choose if you want to build the site as part of the solution or not. If you choose not to, then building the solution is very fast, and you can always click on the Web Site node and select Build, if you’ve made changes.

构建Web应用程序比构建Web站点更快,特别是对于大型站点。这主要是因为Web应用程序不编译标记代码。在MVC中,如果将MvcBuildViews设置为true,则它会编译标记代码并获得错误检测,这非常有用。不好的一面是,每次构建解决方案时,它都会构建完整的站点,这可能会很慢且效率低下,特别是如果您不编辑站点。我发现自己打开和关闭MvcBuildViews(这需要一个项目卸载)。另一方面,使用网站,您可以选择是否要将网站构建为解决方案的一部分。如果您选择不这样做,那么构建解决方案的速度非常快,如果您进行了更改,则可以始终单击“网站”节点并选择“构建”。

In an MVC Web Application project you have extra commands and dialogs for common tasks, like ‘Add View’, ‘Go To View’, ‘Add Controller’, etc. These are not available in an MVC Web Site.

在MVC Web应用程序项目中,您可以使用额外的命令和对话框来执行常见任务,例如“添加视图”,“转到视图”,“添加控制器”等。这些在MVC网站中不可用。

If you use IIS Express as the development server, in Web Sites you can add virtual directories. This option is not available in Web Applications.

如果使用IIS Express作为开发服务器,则可以在“网站”中添加虚拟目录。 Web应用程序中不提供此选项。

NuGet Package Restore does not work on Web Sites, you have to manually install packages listed on packages.config Package Restore now works with Web Sites starting NuGet 2.7

NuGet包还原在网站上不起作用,您必须手动安装在packages.config上列出的包。包恢复现在适用于启动NuGet 2.7的网站

#3


Web Site = use when the website is created by graphic designers and the programmers only edit one or two pages

网站=当图形设计者创建网站时使用,程序员只编辑一页或两页

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

Web应用程序=在程序员创建应用程序时使用,图形设计人员只编辑一个或两个分页/图像。

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.

网站可以使用任何HTML工具而无需开发人员工作室,因为项目文件不需要更新等。当团队主要使用开发人员工作室并且代码内容很高时,Web应用程序是最好的。

(Some coding errors are found in Web Applications at compile time that are not found in Web Sites until run time.)

(在编译时Web应用程序中发现了一些编码错误,这些错误在运行时之前在网站中找不到。)

Warning: I wrote this answer many years ago and have not used Asp.net since. I expect things have now moved on.

警告:我多年前写过这个答案,从那时起就没有使用过Asp.net。我希望事情现在已经开始了。

#4


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 Visual Studio will all take forever on any reasonably sized project. For further information, see the Stack Overflow question Slow “Find All References” in Visual Studio.

为什么?因为在尝试更改或了解您的项目时,网站项目会引起您的反响。 Visual Studio中的静态类型查找功能(例如查找用法,重构)将永远占用任何合理大小的项目。有关详细信息,请参阅Visual Studio中的堆栈溢出问题慢“查找所有引用”。

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

我真的不明白为什么他们在Visual Studio 2005中放弃了Web应用程序,用于引起痛苦,消耗精神,生产力的痈网站项目类型。

#5


There is an article in MSDN which describes the differences:

MSDN中有一篇文章描述了这些差异:

Comparing Web Site Projects and Web Application Projects

比较网站项目和Web应用程序项目

BTW: there are some similar questions about that topic, e.g:

顺便说一句:关于这个话题有一些类似的问题,例如:

#6


This may sound a bit obvious, but I think it's something that is misunderstood because Visual Studio 2005 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.

这可能听起来有点明显,但我认为这是一个被误解的东西,因为Visual Studio 2005最初只附带了网站。如果您的项目涉及的网站相当有限且没有很多逻辑或物理上的分离,那么网站就可以了。但是,如果它是真正的Web应用程序,其中包含许多用户添加和更新数据的不同模块,那么您最好使用Web应用程序。

The biggest pro of the website model is that anything in the app_code section is dynamically compiled. You can make C# 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.

网站模型最大的专业是app_code部分中的任何内容都是动态编译的。您无需完全重新部署即可进行C#文件更新。然而,这是一个巨大的牺牲。许多事情都发生在难以控制的封面之下。命名空间很难控制,默认情况下,app_code下的任何内容都会使特定的DLL使用率超出窗口,因为所有内容都是动态编译的。

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

Web应用程序模型没有动态编译,但您可以控制我提到的内容。

If you are doing n-tier 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.

如果您正在进行n层开发,我强烈推荐Web应用程序模型。如果您正在进行有限的网站或快速而肮脏的实施,则网站模型可能具有优势。

More detailed analysis can be found in:

更详细的分析可以在:

#7


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

来自MCTS自学培训套件考试70-515书:

With web application (project),

使用Web应用程序(项目),

  1. You can create an MVC application.
  2. 您可以创建MVC应用程序。

  3. Visual Studio stores the list of files in a project file (.csproj or .vbproj), rather than relying on the folder structure.
  4. Visual Studio将文件列表存储在项目文件(.csproj或.vbproj)中,而不是依赖于文件夹结构。

  5. You cannot mix Visual Basic and C#.
  6. 你不能混合使用Visual Basic和C#。

  7. You cannot edit code without stopping a debugging session.
  8. 您无法在不停止调试会话的情况下编辑代码。

  9. You can establish dependencies between multiple web projects.
  10. 您可以在多个Web项目之间建立依赖关系。

  11. You must compile the application before deployment, which prevents you from testing a page if another page will not compile.
  12. 您必须在部署之前编译应用程序,这将阻止您在其他页面无法编译时测试页面。

  13. You do not have to store the source code on the server.
  14. 您不必将源代码存储在服务器上。

  15. You can control the assembly name and version.
  16. 您可以控制程序集名称和版本。

  17. You cannot edit individual files after deployment without recompiling.
  18. 无需重新编译即可在部署后编辑单个文件。

#8


It depends on what you are developing.

这取决于你正在开发什么。

A content-oriented website will have its content changing frequently and a Website is better for that.

面向内容的网站的内容会经常变化,网站会更好。

An application tends to have its data stored in a database and its pages and code change rarely. In this case it's better to have a Web application where deployment of assemblies is much more controlled and has better support for unit testing.

应用程序往往将其数据存储在数据库中,其页面和代码很少发生变化。在这种情况下,最好有一个Web应用程序,其中组件的部署受到更多控制,并且对单元测试有更好的支持。

#9


Compilation Firstly there is a difference in compilation. Web Site is not pre-compiled on server, it is compiled on file. It may be an advantage because when you want to change something in your Web Site you can just download a specific file from server, change it and upload this file back to server and everything would work fine. In Web Application you can't do this because everthing is pre-compiled and you end up with only one dll. When you change something in one file of your project you have to re-compile everything again. So if you would like to have a possibility to change some files on server Web Site is better solution for you. It also allows many developers to work on one Web Site. On the other side, if you don't want your code to be available on server you should rather choose Web Application. This option is also better for Unit Testing because of one DLL file being created after publishing your website.

编译首先编译有所不同。 Web站点未在服务器上预编译,它是在文件上编译的。这可能是一个优势,因为当您想要更改网站中的某些内容时,您只需从服务器下载特定文件,更改它并将此文件上传回服务器,一切都会正常工作。在Web应用程序中,您不能这样做,因为everthing是预编译的,并且您最终只有一个dll。当您在项目的一个文件中更改某些内容时,您必须重新编译所有内容。因此,如果您希望有可能更改服务器上的某些文件,网站是更好的解决方案。它还允许许多开发人员在一个网站上工作。另一方面,如果您不希望代码在服务器上可用,则应选择Web应用程序。此选项对于单元测试也更好,因为在发布网站后创建了一个DLL文件。

Project structure There is also a difference in the structure of the project. In Web Application you have a project file just like you had it in normal application. In Web Site there is no traditional project file, all you have is solution file. All references and settings are stored in web.config file.@Page directive There is a different attribute in @Page directive for the file that contains class associated with this page. In Web Application it is standard "CodeBehind", in Web Site you use "CodeFile". You can see this in the examples below:

项目结构项目结构也存在差异。在Web应用程序中,您有一个项目文件,就像在普通应用程序中一样。在网站上没有传统的项目文件,你只有解决方案文件。所有引用和设置都存储在web.config文件中。@ Page指令@Page指令中包含与该页面关联的类的文件的不同属性。在Web应用程序中,它是标准的“CodeBehind”,在网站中使用“CodeFile”。您可以在以下示例中看到:

Web Application:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"  Inherits="WebApplication._Default" %>  

Web Site:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

Namespaces - In the example above you can see also another difference - how namespaces are created. In Web Application namespace is simply a name of the project. In Website there is default namespace ASP for dynamically compiled pages.

命名空间 - 在上面的示例中,您还可以看到另一个区别 - 如何创建命名空间。在Web Application中,名称空间只是项目的名称。在Website中,有动态编译页面的默认命名空间ASP。

Edit and Continue- In Web Application Edit and Continue option is available (to turn it on you have to go to Tools Menu, click Options then find Edit and Continue in Debugging). This feature is not working in Web Site.ASP.NET MVCIf you want to develop web applications using

编辑并继续 - 在Web应用程序中编辑并继续选项可用(要打开它,您必须转到“工具”菜单,单击“选项”,然后在“调试”中找到“编辑并继续”)。此功能在Web Site.ASP.NET MVCIf中无法使用,您希望使用开发Web应用程序

ASP.NET MVC (Model View Controller) the best and default option is Web Application. Although it's possible to use MVC in Web Site it's not recommended.

ASP.NET MVC(模型视图控制器)最好的默认选项是Web应用程序。虽然可以在网站上使用MVC,但不建议这样做。

Summary - The most important difference between ASP.NET Web Application and Web Site is compilation. So if you work on a bigger project where a few people can modify it it's better to use Web Site. But if you're doing a smaller project you can use Web Application as well.

总结 - ASP.NET Web应用程序和Web站点之间最重要的区别是编译。因此,如果你在一个更大的项目上工作,少数人可以修改它,最好使用网站。但是如果你正在做一个较小的项目,你也可以使用Web应用程序。

#10


Yes web application is much better than web sites, because Web applications give us freedom:

是的Web应用程序比Web站点要好得多,因为Web应用程序为我们提供了*:

  1. To have multiple projects under one umbrella and establish projectdependencies between. E.g. for PCS we can have following within webapplication-

    在一个保护伞下建立多个项目并建立项目依赖关系。例如。对于PCS,我们可以在webapplication中进行以下操作 -

    • Web portals
    • Notification Controller (for sending Email)
    • 通知控制器(用于发送电子邮件)

    • Business layer
    • Data Access layer
    • 数据访问层

    • Exception Manager
    • Server utility
    • WCF Services (Common for all platforms)
    • WCF服务(适用于所有平台)

    • List item
  2. To run unit tests on code that is in the class files that areassociated with ASP.NET pages

    对与ASP.NET页面关联的类文件中的代码运行单元测试

  3. To refer to the classes those areassociated with pages and user controls from standalone classes
  4. 要引用那些与独立类中的页面和用户控件关联的区域

  5. To create a single assembly for the entire site
  6. 为整个站点创建单个程序集

  7. Control over the assembly name and version number that is generated for the site
  8. 控制为站点生成的程序集名称和版本号

  9. To avoid putting source code on a production server. (You can avoiddeploying source code to the IIS server. In some scenarios, such asshared hosting environments, you might be concerned aboutunauthorized access to source code on the IIS server. (For a website project, you can avoid this risk by pre-compiling on adevelopment computer and deploying the generated assemblies insteadof the source code. However, in that case you lose some of thebenefits of easy site updates.)
  10. 避免将源代码放在生产服务器上。 (您可以避免将源代码部署到IIS服务器。在某些情况下,这样的共享托管环境,您可能会担心在IIS服务器上对源代码进行无限制访问。(对于网站项目,您可以通过预编译来避免此风险开发计算机并部署生成的程序集而不是源代码。但是,在这种情况下,您将失去一些简单的站点更新的好处。)

  11. Performance Issue with Website(Thefirst request to the web site might require the site to be compiled,which can result in a delay. And if the web site is running on anIIS server that is short on memory, including the entire site in asingle assembly might use more memory than would be required formultiple assemblies.)
  12. 网站的性能问题(对网站的第一次请求可能需要编译网站,这可能会导致延迟。如果网站在内存不足的IE服务器上运行,包括整个网站在单个程序集中可能使用比多个程序集所需的内存更多的内存。)

#11


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

其中一个主要区别是网站动态编译并创建动态组件。 Web应用程序编译成一个大型程序集。

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

在Visual Studio 2008中已经完成了两者之间的区别。

#12


Applications are usually compiled before deployment where as the website makes use of the app_code directory. When anything changes in the app code folder the server will re-compile the code. This means that you can add/ change code with a website on the fly.

应用程序通常在部署之前编译,因为网站使用app_code目录。当应用程序代码文件夹中的任何更改时,服务器将重新编译代码。这意味着您可以动态地添加/更改代码。

The advantage of an app is that there is no re-compiling and so initial start up times will be faster.

应用程序的优势在于没有重新编译,因此初始启动时间会更快。

#13


I recommend you watch the video Web Application Projects & Web Deployment Projects on the ASP.NET website which explains the difference in great detail, it was quite helpful to me.

我建议您在ASP.NET网站上观看视频Web应用程序项目和Web部署项目,这些项目非常详细地解释了它们,这对我很有帮助。

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.

顺便说一下,不要对标题感到困惑,视频的很大一部分解释了网站项目和Web应用程序项目之间的区别以及Microsoft为何在Visual Studio 2005中重新引入Web应用程序项目(正如您可能已经知道的那样)最初只附带网站项目,然后在SP1中添加了Web应用程序项目)。对于想要了解差异的人,我强烈推荐一个很棒的视频。

#14


A "web site" has its code in a special App_Code directory and it's compiled into several DLLs (assemblies) at runtime. A "web application" is precompiled into one single DLL.

“网站”将其代码放在特殊的App_Code目录中,并在运行时将其编译为多个DLL(程序集)。 “Web应用程序”预编译为一个DLL。

#15


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

网站和项目>>网站是使用visual studio创建ASP.NET应用程序的两种不同方法。一种是无项目的,另一种是项目环境。差异如下

  1. Solution file is stored in same directory as root directory in project environment.
  2. 解决方案文件与项目环境中的根目录存储在同一目录中。

  3. Need to remove solution and project files before deploying in project environment.
  4. 在项目环境中部署之前,需要删除解决方案和项目文件。

  5. Complete root directory is deployed in projectless environment.
  6. 完整的根目录部署在无项目环境中。

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

使用任何一种方法都没有太大的区别。但是,如果您要创建需要更长时间的网站,请选择项目环境。

#16


Web Application project model

Web应用程序项目模型

  • Provides the same Web project semantics as Visual Studio .NET Webprojects. Has a project file (structure based on project files).Build model - all code in the project is compiled into a singleassembly. Supports both IIS and the built-in ASP.NET DevelopmentServer. Supports all the features of Visual Studio 2005 (refactoring,generics, etc.) and of ASP.NET (master pages, membership and login,site navigation, themes, etc). Using FrontPage Server Extensions(FPSE) are no longer a requirement.
  • 提供与Visual Studio .NET Webproject相同的Web项目语义。有项目文件(基于项目文件的结构).Build模型 - 项目中的所有代码都被编译成单个组件。支持IIS和内置的ASP.NET DevelopmentServer。支持Visual Studio 2005(重构,泛型等)和ASP.NET(母版页,成员资格和登录,网站导航,主题等)的所有功能。不再需要使用FrontPage Server Extensions(FPSE)。

Web Site project model

网站项目模型

  • No project file (Based on file system).
  • 没有项目文件(基于文件系统)。

  • New compilation model.
  • 新的编译模型。

  • Dynamic compilation and working on pages without building entire siteon each page view.
  • 动态编译和处理页面而不在每个页面视图中构建整个站点。

  • Supports both IIS and the built-in ASP.NET Development Server.
  • 支持IIS和内置的ASP.NET开发服务器。

  • Each page has it's own assembly.
  • 每个页面都有自己的程序集。

  • Defferent code model.
  • 不同的代码模型。

#17


It is always depends on the requirement of your client. ASP.NET just includes flexible features that the user needs for security and easy maintenance of your application.

它始终取决于您的客户的要求。 ASP.NET只包含用户安全性和易于维护应用程序所需的灵活功能。

You can think of a Web application as a binary file that runs inside the ASP.NET framework. And Web sites as a static webpage that you can review and easily deploy source code to.

您可以将Web应用程序视为在ASP.NET框架内运行的二进制文件。而网站作为静态网页,您可以查看并轻松部署源代码。

But the advantage and disadvantages of these two ASP.NET technologies come what is good.

但是这两种ASP.NET技术的优点和缺点都是有益的。

#18


Websites - No solution file will be created. If we want to create websites no need for visual studio.

网站 - 不会创建解决方案文件。如果我们想创建不需要Visual Studio的网站。

Web Application - A solution file will be created. If we want to create web application should need the visual studio. It will create a single .dll file in bin folder.

Web应用程序 - 将创建解决方案文件。如果我们要创建Web应用程序,则需要Visual Studio。它将在bin文件夹中创建一个.dll文件。

#19


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.

在Web应用程序项目中,Visual Studio需要用于页面和用户控件的其他.designer文件。网站项目不需要这种开销。标记本身被解释为设计。

#20


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.

WebSite:它会自动生成app_code文件夹,如果您在服务器上发布它,之后如果您在任何特定文件或页面中进行某些更改,则不必编译所有文件。

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.

Web应用程序它自动生成解决方案文件,哪个网站不生成,如果您更改一个文件,则必须编译完整项目以反映其更改。

#21


In a web application you can create the layers of your project's functionality and can create inter-dependencies between them by dividing it into many projects, but you can never do this on a website.

在Web应用程序中,您可以创建项目功能的各个层,并通过将它们划分为多个项目来创建它们之间的相互依赖关系,但您永远不能在网站上执行此操作。

#22


Definitely web application, single DLL file and easy to maintain. But a website is more flexible; you can edit the aspx file on the go.

绝对是Web应用程序,单个DLL文件,易于维护。但是网站更灵活;你可以随时编辑aspx文件。

#23


Web applications require more memory, presumably because you have no choice but to compile into a single assembly. I just converted a large legacy site to a web application and have issues with running out of memory, both at compile time with the error message as below :

Web应用程序需要更多内存,大概是因为您别无选择只能编译成单个程序集。我刚刚将一个大型遗留站点转换为Web应用程序,并且在编译时出现内存不足的问题,并显示如下错误消息:

Unexpected error writing metadata to file '' -- Not enough storage is available to complete this operation. 

error, and at runtime with this error message as below :

错误,并在运行时出现此错误消息,如下所示:

Exception information:     Exception type: HttpException     Exception message: Exception of type 'System.OutOfMemoryException' was thrown.   at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()

My recommendation for converting larger sites on memory-constrained legacy hardware is, to choose the option to revert back to the web site model. Even after an initial success problem might creep up later.

我建议在内存受限的旧硬件上转换大型网站,选择恢复为网站模型的选项。即使在最初的成功问题可能会在以后蔓延。

#24


ASP.NET网站或ASP.NET Web应用程序?

Here Web Supportive Application is an example of website.Website and Web Application both can be dynamic/static its depends upon requirements, here is an example to understand working of website's and web application.

这里Web支持应用程序是一个网站的例子。网站和Web应用程序都可以是动态/静态的,它取决于要求,这里是一个了解网站和Web应用程序工作的例子。

#25


To summarize some of the answers above:

总结一下上面的一些答案:

Flexibility, can you can make live changes to a web page?

灵活性,您可以对网页进行实时更改吗?

Web Site: Possible. Pro: short term benefits. Con: long term risk of project chaos.

网站:可能。亲:短期利益。骗局:项目混乱的长期风险。

Web App: Con: not possible. Edit a page, archive the changes to source control, then build and deploy the entire site. Pro: maintain a quality project.

Web App:Con:不可能。编辑页面,将更改存档到源控件,然后构建和部署整个站点。亲:保持优质项目。

Development issues

Web Site: Simple project structure without a .csproj file.Two .aspx pages may have the same class name without conflicts. Random project directory name leading to build errors like why .net framework conflicts with its own generated file and why .net framework conflicts with its own generated file. Pro: Simple (simplistic). Con: erratic.

网站:没有.csproj文件的简单项目结构。两个.aspx页面可能具有相同的类名而没有冲突。随机项目目录名称导致构建错误,例如.net框架与其自己生成的文件冲突的原因以及.net框架与其自己生成的文件冲突的原因。亲:简单(简单)。骗局:不稳定。

Web App: Project structure similar to WebForms project, with a .csproj file. Class names of asp pages must be unique. Pro: Simple (smart). Con: none, because a web app is still simple.

Web App:类似于WebForms项目的项目结构,带有.csproj文件。 asp页面的类名必须是唯一的。亲:简单(聪明)。骗局:没有,因为网络应用仍然很简单。

#1


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.

Web站点项目即时编译。你最终得到了更多的DLL文件,这可能是一个痛苦。当您在一个目录中有页面或控件需要引用另一个目录中的页面和控件时,它也会出现问题,因为其他目录可能尚未编译到代码中。另一个问题可能是出版。

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.

如果没有告诉Visual Studio不断重复使用相同的名称,它将为页面始终生成的DLL文件提供新名称。这可能会导致包含相同类名的DLL文件的几个密切副本,这将产生大量错误。 Web站点项目是在Visual Studio 2005中引入的,但事实并非如此受欢迎。

Web Application:

The Web Application Project was created as an add-in and now exists as partof SP 1 for Visual Studio 2005. The main differences are the Web Application Projectwas 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 buildtime. In order to update the project, it must be recompiled and the DLL filepublished for changes to occur.

Web应用程序项目是作为加载项创建的,现在作为Visual Studio 2005的SP 1的一部分存在。主要区别在于Web应用程序项目的设计类似于Visual Studio 2003附带的Web项目。它将编译在构建时将应用程序应用到单个DLL文件中。为了更新项目,必须重新编译它,并发布DLL文件以进行更改。

Another nice feature of the Web Applicationproject is it's much easier to exclude files from the project view. In theWeb Site project, each file that you exclude is renamed with an excludedkeyword in the filename. In the Web Application Project, the project justkeeps track of which files to include/exclude from the project view withoutrenaming them, making things much tidier.

Web Applicationproject的另一个不错的功能是从项目视图中排除文件要容易得多。在“Web站点”项目中,您排除的每个文件都使用文件名中的excludedkeyword重命名。在Web应用程序项目中,项目只是跟踪从项目视图中包含/排除哪些文件而不重命名它们,使事情变得更加整洁。

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:

文章ASP.NET 2.0 - Web站点与Web应用程序项目也给出了为什么使用一个而不是另一个的原因。以下是它的摘录:

  • You need to migrate large Visual Studio .NET 2003 applications to VS 2005? use the Web Application project.
  • 您需要将大型Visual Studio .NET 2003应用程序迁移到VS 2005吗?使用Web应用程序项目。

  • You want to open and edit any directory as a Web project without creating a project file? use Web Site project.
  • 您想在不创建项目文件的情况下打开和编辑任何目录作为Web项目吗?使用网站项目。

  • You need to add pre-build and post-build steps during compilation? use Web Application project.
  • 您需要在编译期间添加预构建和后构建步骤吗?使用Web应用程序项目。

  • You need to build a Web application using multiple Web projects? use Web Application project.
  • 您需要使用多个Web项目构建Web应用程序吗?使用Web应用程序项目。

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

Web应用程序项目与Web站点项目(MSDN)解释了Web站点和Web应用程序项目之间的差异。此外,它还讨论了在Visual Studio中进行的配置。

#2


Web Site is what you deploy to an ASP.NET web server such as IIS. Just a bunch of files and folders. There’s nothing in a Web Site that ties you to Visual Studio (there’s no project file). Code-generation and compilation of web pages (such as .aspx, .ascx, .master) is done dynamically at runtime, and changes to these files are detected by the framework and automatically re-compiled. You can put code that you want to share between pages in the special App_Code folder, or you can pre-compile it and put the assembly in the Bin folder.

Web站点是您部署到ASP.NET Web服务器(如IIS)的内容。只是一堆文件和文件夹。网站中没有任何内容可以将您与Visual Studio联系起来(没有项目文件)。代码生成和网页编译(例如.aspx,.ascx,.master)在运行时动态完成,框架检测到这些文件的更改并自动重新编译。您可以在特殊的App_Code文件夹中放置要在页面之间共享的代码,也可以预编译它并将程序集放在Bin文件夹中。

Web Application is a special Visual Studio project. The main difference with Web Sites is that when you build the project all the code files are compiled into a single assembly, which is placed in the bin directory. You don’t deploy code files to the web server. Instead of having a special folder for shared code files you can put them anywhere, just like you would do in class library. Because Web Applications contains files that are not meant to be deployed, such as project and code files, there’s a Publish command in Visual Studio to output a Web Site to a specified location.

Web应用程序是一个特殊的Visual Studio项目。与Web站点的主要区别在于,在构建项目时,所有代码文件都编译为单个程序集,该程序集位于bin目录中。您不会将代码文件部署到Web服务器。您可以将它们放在任何位置,而不是像在类库中那样放置共享代码文件的特殊文件夹。由于Web应用程序包含不打算部署的文件(例如项目和代码文件),因此Visual Studio中有一个“发布”命令可将网站输出到指定位置。

App_Code vs Bin

Deploying shared code files is generally a bad idea, but that doesn’t mean you have to choose Web Application. You can have a Web Site that references a class library project that holds all the code for the Web Site. Web Applications is just a convenient way to do it.

部署共享代码文件通常是个坏主意,但这并不意味着您必须选择Web应用程序。您可以拥有一个引用类库项目的Web站点,该项目包含Web站点的所有代码。 Web应用程序只是一种方便的方法。

CodeBehind

This topic is specific to .aspx and .ascx files. This topic is decreasingly relevant in new application frameworks such as ASP.NET MVC and ASP.NET Web Pages which do not use codebehind files.

本主题特定于.aspx和.ascx文件。在不使用代码隐藏文件的ASP.NET MVC和ASP.NET Web页面等新应用程序框架中,此主题越来越相关。

By having all code files compiled into a single assembly, including codebehind files of .aspx pages and .ascx controls, in Web Applications 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 Web Sites changes are detected by the runtime and pages/controls are automatically recompiled.

通过将所有代码文件编译为单个程序集(包括.aspx页面和.ascx控件的代码隐藏文件),在Web应用程序中,您必须为每个小的更改重新构建,并且您无法进行实时更改。这在开发过程中可能是一个真正的痛苦,因为您必须不断重新构建以查看更改,而运行时检测到Web站点更改并自动重新编译页面/控件。

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

让运行时管理代码隐藏程序集对您来说不那么重要,因为您不必担心为页面/控件提供唯一名称,或者将它们组织到不同的名称空间中。

I’m not saying deploying code files is always a good idea (specially not in the case of shared code files), but codebehind files should only contain code that perform UI specific tasks, wire-up events handlers, etc. Your application should be layered so that important code always end up in the Bin folder. If that is the case then deploying codebehind files shouldn't be considered harmful.

我不是说部署代码文件总是一个好主意(特别是在共享代码文件的情况下),但代码隐藏文件应该只包含执行UI特定任务的代码,连接事件处理程序等。您的应用程序应该是分层,以便重要的代码总是在Bin文件夹中。如果是这种情况,那么部署代码隐藏文件不应被视为有害。

Another limitation of Web Applications is that you can only use the language of the project. In Web Sites you can have some pages in C#, some in VB, etc. No need for special Visual Studio support. That’s the beauty of the build provider extensibility.

Web应用程序的另一个限制是您只能使用项目的语言。在网站中,您可以在C#中创建一些页面,在VB中使用一些页面等。不需要特殊的Visual Studio支持。这就是构建提供程序可扩展性的美妙之处。

Also, in Web Applications you don't get error detection in pages/controls as the compiler only compiles your codebehind classes and not the markup code (in MVC you can fix this using the MvcBuildViews option), which is compiled at runtime.

此外,在Web应用程序中,您不会在页面/控件中获得错误检测,因为编译器只编译您的代码隐藏类而不是标记代码(在MVC中您可以使用MvcBuildViews选项修复此问题),这是在运行时编译的。

Visual Studio

Because Web Applications are Visual Studio projects you get some features not available in Web Sites. For instance, you can use build events to perform a variety of tasks, e.g. minify and/or combine Javascript files.

由于Web应用程序是Visual Studio项目,因此您将获得Web站点中不具备的一些功能。例如,您可以使用构建事件来执行各种任务,例如缩小和/或组合Javascript文件。

Another nice feature introduced in Visual Studio 2010 is Web.config transformation. This is also not available in Web Sites. Now works with Web Sites in VS 2013.

Visual Studio 2010中引入的另一个不错的功能是Web.config转换。这在网站中也不可用。现在可以在VS 2013中使用网站。

Building a Web Application is faster than building a Web Site, specially for large sites. This is mainly because Web Applications do not compile the markup code. In MVC if you set MvcBuildViews to true then it compiles the markup code and you get error detection, which is very useful. The down side is that every time you build the solution it builds the complete site, which can be slow and inefficient, specially if you are not editing the site. l find myself turning MvcBuildViews on and off (which requires a project unload). On the other hand, with Web Sites you can choose if you want to build the site as part of the solution or not. If you choose not to, then building the solution is very fast, and you can always click on the Web Site node and select Build, if you’ve made changes.

构建Web应用程序比构建Web站点更快,特别是对于大型站点。这主要是因为Web应用程序不编译标记代码。在MVC中,如果将MvcBuildViews设置为true,则它会编译标记代码并获得错误检测,这非常有用。不好的一面是,每次构建解决方案时,它都会构建完整的站点,这可能会很慢且效率低下,特别是如果您不编辑站点。我发现自己打开和关闭MvcBuildViews(这需要一个项目卸载)。另一方面,使用网站,您可以选择是否要将网站构建为解决方案的一部分。如果您选择不这样做,那么构建解决方案的速度非常快,如果您进行了更改,则可以始终单击“网站”节点并选择“构建”。

In an MVC Web Application project you have extra commands and dialogs for common tasks, like ‘Add View’, ‘Go To View’, ‘Add Controller’, etc. These are not available in an MVC Web Site.

在MVC Web应用程序项目中,您可以使用额外的命令和对话框来执行常见任务,例如“添加视图”,“转到视图”,“添加控制器”等。这些在MVC网站中不可用。

If you use IIS Express as the development server, in Web Sites you can add virtual directories. This option is not available in Web Applications.

如果使用IIS Express作为开发服务器,则可以在“网站”中添加虚拟目录。 Web应用程序中不提供此选项。

NuGet Package Restore does not work on Web Sites, you have to manually install packages listed on packages.config Package Restore now works with Web Sites starting NuGet 2.7

NuGet包还原在网站上不起作用,您必须手动安装在packages.config上列出的包。包恢复现在适用于启动NuGet 2.7的网站

#3


Web Site = use when the website is created by graphic designers and the programmers only edit one or two pages

网站=当图形设计者创建网站时使用,程序员只编辑一页或两页

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

Web应用程序=在程序员创建应用程序时使用,图形设计人员只编辑一个或两个分页/图像。

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.

网站可以使用任何HTML工具而无需开发人员工作室,因为项目文件不需要更新等。当团队主要使用开发人员工作室并且代码内容很高时,Web应用程序是最好的。

(Some coding errors are found in Web Applications at compile time that are not found in Web Sites until run time.)

(在编译时Web应用程序中发现了一些编码错误,这些错误在运行时之前在网站中找不到。)

Warning: I wrote this answer many years ago and have not used Asp.net since. I expect things have now moved on.

警告:我多年前写过这个答案,从那时起就没有使用过Asp.net。我希望事情现在已经开始了。

#4


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 Visual Studio will all take forever on any reasonably sized project. For further information, see the Stack Overflow question Slow “Find All References” in Visual Studio.

为什么?因为在尝试更改或了解您的项目时,网站项目会引起您的反响。 Visual Studio中的静态类型查找功能(例如查找用法,重构)将永远占用任何合理大小的项目。有关详细信息,请参阅Visual Studio中的堆栈溢出问题慢“查找所有引用”。

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

我真的不明白为什么他们在Visual Studio 2005中放弃了Web应用程序,用于引起痛苦,消耗精神,生产力的痈网站项目类型。

#5


There is an article in MSDN which describes the differences:

MSDN中有一篇文章描述了这些差异:

Comparing Web Site Projects and Web Application Projects

比较网站项目和Web应用程序项目

BTW: there are some similar questions about that topic, e.g:

顺便说一句:关于这个话题有一些类似的问题,例如:

#6


This may sound a bit obvious, but I think it's something that is misunderstood because Visual Studio 2005 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.

这可能听起来有点明显,但我认为这是一个被误解的东西,因为Visual Studio 2005最初只附带了网站。如果您的项目涉及的网站相当有限且没有很多逻辑或物理上的分离,那么网站就可以了。但是,如果它是真正的Web应用程序,其中包含许多用户添加和更新数据的不同模块,那么您最好使用Web应用程序。

The biggest pro of the website model is that anything in the app_code section is dynamically compiled. You can make C# 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.

网站模型最大的专业是app_code部分中的任何内容都是动态编译的。您无需完全重新部署即可进行C#文件更新。然而,这是一个巨大的牺牲。许多事情都发生在难以控制的封面之下。命名空间很难控制,默认情况下,app_code下的任何内容都会使特定的DLL使用率超出窗口,因为所有内容都是动态编译的。

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

Web应用程序模型没有动态编译,但您可以控制我提到的内容。

If you are doing n-tier 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.

如果您正在进行n层开发,我强烈推荐Web应用程序模型。如果您正在进行有限的网站或快速而肮脏的实施,则网站模型可能具有优势。

More detailed analysis can be found in:

更详细的分析可以在:

#7


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

来自MCTS自学培训套件考试70-515书:

With web application (project),

使用Web应用程序(项目),

  1. You can create an MVC application.
  2. 您可以创建MVC应用程序。

  3. Visual Studio stores the list of files in a project file (.csproj or .vbproj), rather than relying on the folder structure.
  4. Visual Studio将文件列表存储在项目文件(.csproj或.vbproj)中,而不是依赖于文件夹结构。

  5. You cannot mix Visual Basic and C#.
  6. 你不能混合使用Visual Basic和C#。

  7. You cannot edit code without stopping a debugging session.
  8. 您无法在不停止调试会话的情况下编辑代码。

  9. You can establish dependencies between multiple web projects.
  10. 您可以在多个Web项目之间建立依赖关系。

  11. You must compile the application before deployment, which prevents you from testing a page if another page will not compile.
  12. 您必须在部署之前编译应用程序,这将阻止您在其他页面无法编译时测试页面。

  13. You do not have to store the source code on the server.
  14. 您不必将源代码存储在服务器上。

  15. You can control the assembly name and version.
  16. 您可以控制程序集名称和版本。

  17. You cannot edit individual files after deployment without recompiling.
  18. 无需重新编译即可在部署后编辑单个文件。

#8


It depends on what you are developing.

这取决于你正在开发什么。

A content-oriented website will have its content changing frequently and a Website is better for that.

面向内容的网站的内容会经常变化,网站会更好。

An application tends to have its data stored in a database and its pages and code change rarely. In this case it's better to have a Web application where deployment of assemblies is much more controlled and has better support for unit testing.

应用程序往往将其数据存储在数据库中,其页面和代码很少发生变化。在这种情况下,最好有一个Web应用程序,其中组件的部署受到更多控制,并且对单元测试有更好的支持。

#9


Compilation Firstly there is a difference in compilation. Web Site is not pre-compiled on server, it is compiled on file. It may be an advantage because when you want to change something in your Web Site you can just download a specific file from server, change it and upload this file back to server and everything would work fine. In Web Application you can't do this because everthing is pre-compiled and you end up with only one dll. When you change something in one file of your project you have to re-compile everything again. So if you would like to have a possibility to change some files on server Web Site is better solution for you. It also allows many developers to work on one Web Site. On the other side, if you don't want your code to be available on server you should rather choose Web Application. This option is also better for Unit Testing because of one DLL file being created after publishing your website.

编译首先编译有所不同。 Web站点未在服务器上预编译,它是在文件上编译的。这可能是一个优势,因为当您想要更改网站中的某些内容时,您只需从服务器下载特定文件,更改它并将此文件上传回服务器,一切都会正常工作。在Web应用程序中,您不能这样做,因为everthing是预编译的,并且您最终只有一个dll。当您在项目的一个文件中更改某些内容时,您必须重新编译所有内容。因此,如果您希望有可能更改服务器上的某些文件,网站是更好的解决方案。它还允许许多开发人员在一个网站上工作。另一方面,如果您不希望代码在服务器上可用,则应选择Web应用程序。此选项对于单元测试也更好,因为在发布网站后创建了一个DLL文件。

Project structure There is also a difference in the structure of the project. In Web Application you have a project file just like you had it in normal application. In Web Site there is no traditional project file, all you have is solution file. All references and settings are stored in web.config file.@Page directive There is a different attribute in @Page directive for the file that contains class associated with this page. In Web Application it is standard "CodeBehind", in Web Site you use "CodeFile". You can see this in the examples below:

项目结构项目结构也存在差异。在Web应用程序中,您有一个项目文件,就像在普通应用程序中一样。在网站上没有传统的项目文件,你只有解决方案文件。所有引用和设置都存储在web.config文件中。@ Page指令@Page指令中包含与该页面关联的类的文件的不同属性。在Web应用程序中,它是标准的“CodeBehind”,在网站中使用“CodeFile”。您可以在以下示例中看到:

Web Application:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"  Inherits="WebApplication._Default" %>  

Web Site:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

Namespaces - In the example above you can see also another difference - how namespaces are created. In Web Application namespace is simply a name of the project. In Website there is default namespace ASP for dynamically compiled pages.

命名空间 - 在上面的示例中,您还可以看到另一个区别 - 如何创建命名空间。在Web Application中,名称空间只是项目的名称。在Website中,有动态编译页面的默认命名空间ASP。

Edit and Continue- In Web Application Edit and Continue option is available (to turn it on you have to go to Tools Menu, click Options then find Edit and Continue in Debugging). This feature is not working in Web Site.ASP.NET MVCIf you want to develop web applications using

编辑并继续 - 在Web应用程序中编辑并继续选项可用(要打开它,您必须转到“工具”菜单,单击“选项”,然后在“调试”中找到“编辑并继续”)。此功能在Web Site.ASP.NET MVCIf中无法使用,您希望使用开发Web应用程序

ASP.NET MVC (Model View Controller) the best and default option is Web Application. Although it's possible to use MVC in Web Site it's not recommended.

ASP.NET MVC(模型视图控制器)最好的默认选项是Web应用程序。虽然可以在网站上使用MVC,但不建议这样做。

Summary - The most important difference between ASP.NET Web Application and Web Site is compilation. So if you work on a bigger project where a few people can modify it it's better to use Web Site. But if you're doing a smaller project you can use Web Application as well.

总结 - ASP.NET Web应用程序和Web站点之间最重要的区别是编译。因此,如果你在一个更大的项目上工作,少数人可以修改它,最好使用网站。但是如果你正在做一个较小的项目,你也可以使用Web应用程序。

#10


Yes web application is much better than web sites, because Web applications give us freedom:

是的Web应用程序比Web站点要好得多,因为Web应用程序为我们提供了*:

  1. To have multiple projects under one umbrella and establish projectdependencies between. E.g. for PCS we can have following within webapplication-

    在一个保护伞下建立多个项目并建立项目依赖关系。例如。对于PCS,我们可以在webapplication中进行以下操作 -

    • Web portals
    • Notification Controller (for sending Email)
    • 通知控制器(用于发送电子邮件)

    • Business layer
    • Data Access layer
    • 数据访问层

    • Exception Manager
    • Server utility
    • WCF Services (Common for all platforms)
    • WCF服务(适用于所有平台)

    • List item
  2. To run unit tests on code that is in the class files that areassociated with ASP.NET pages

    对与ASP.NET页面关联的类文件中的代码运行单元测试

  3. To refer to the classes those areassociated with pages and user controls from standalone classes
  4. 要引用那些与独立类中的页面和用户控件关联的区域

  5. To create a single assembly for the entire site
  6. 为整个站点创建单个程序集

  7. Control over the assembly name and version number that is generated for the site
  8. 控制为站点生成的程序集名称和版本号

  9. To avoid putting source code on a production server. (You can avoiddeploying source code to the IIS server. In some scenarios, such asshared hosting environments, you might be concerned aboutunauthorized access to source code on the IIS server. (For a website project, you can avoid this risk by pre-compiling on adevelopment computer and deploying the generated assemblies insteadof the source code. However, in that case you lose some of thebenefits of easy site updates.)
  10. 避免将源代码放在生产服务器上。 (您可以避免将源代码部署到IIS服务器。在某些情况下,这样的共享托管环境,您可能会担心在IIS服务器上对源代码进行无限制访问。(对于网站项目,您可以通过预编译来避免此风险开发计算机并部署生成的程序集而不是源代码。但是,在这种情况下,您将失去一些简单的站点更新的好处。)

  11. Performance Issue with Website(Thefirst request to the web site might require the site to be compiled,which can result in a delay. And if the web site is running on anIIS server that is short on memory, including the entire site in asingle assembly might use more memory than would be required formultiple assemblies.)
  12. 网站的性能问题(对网站的第一次请求可能需要编译网站,这可能会导致延迟。如果网站在内存不足的IE服务器上运行,包括整个网站在单个程序集中可能使用比多个程序集所需的内存更多的内存。)

#11


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

其中一个主要区别是网站动态编译并创建动态组件。 Web应用程序编译成一个大型程序集。

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

在Visual Studio 2008中已经完成了两者之间的区别。

#12


Applications are usually compiled before deployment where as the website makes use of the app_code directory. When anything changes in the app code folder the server will re-compile the code. This means that you can add/ change code with a website on the fly.

应用程序通常在部署之前编译,因为网站使用app_code目录。当应用程序代码文件夹中的任何更改时,服务器将重新编译代码。这意味着您可以动态地添加/更改代码。

The advantage of an app is that there is no re-compiling and so initial start up times will be faster.

应用程序的优势在于没有重新编译,因此初始启动时间会更快。

#13


I recommend you watch the video Web Application Projects & Web Deployment Projects on the ASP.NET website which explains the difference in great detail, it was quite helpful to me.

我建议您在ASP.NET网站上观看视频Web应用程序项目和Web部署项目,这些项目非常详细地解释了它们,这对我很有帮助。

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.

顺便说一下,不要对标题感到困惑,视频的很大一部分解释了网站项目和Web应用程序项目之间的区别以及Microsoft为何在Visual Studio 2005中重新引入Web应用程序项目(正如您可能已经知道的那样)最初只附带网站项目,然后在SP1中添加了Web应用程序项目)。对于想要了解差异的人,我强烈推荐一个很棒的视频。

#14


A "web site" has its code in a special App_Code directory and it's compiled into several DLLs (assemblies) at runtime. A "web application" is precompiled into one single DLL.

“网站”将其代码放在特殊的App_Code目录中,并在运行时将其编译为多个DLL(程序集)。 “Web应用程序”预编译为一个DLL。

#15


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

网站和项目>>网站是使用visual studio创建ASP.NET应用程序的两种不同方法。一种是无项目的,另一种是项目环境。差异如下

  1. Solution file is stored in same directory as root directory in project environment.
  2. 解决方案文件与项目环境中的根目录存储在同一目录中。

  3. Need to remove solution and project files before deploying in project environment.
  4. 在项目环境中部署之前,需要删除解决方案和项目文件。

  5. Complete root directory is deployed in projectless environment.
  6. 完整的根目录部署在无项目环境中。

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

使用任何一种方法都没有太大的区别。但是,如果您要创建需要更长时间的网站,请选择项目环境。

#16


Web Application project model

Web应用程序项目模型

  • Provides the same Web project semantics as Visual Studio .NET Webprojects. Has a project file (structure based on project files).Build model - all code in the project is compiled into a singleassembly. Supports both IIS and the built-in ASP.NET DevelopmentServer. Supports all the features of Visual Studio 2005 (refactoring,generics, etc.) and of ASP.NET (master pages, membership and login,site navigation, themes, etc). Using FrontPage Server Extensions(FPSE) are no longer a requirement.
  • 提供与Visual Studio .NET Webproject相同的Web项目语义。有项目文件(基于项目文件的结构).Build模型 - 项目中的所有代码都被编译成单个组件。支持IIS和内置的ASP.NET DevelopmentServer。支持Visual Studio 2005(重构,泛型等)和ASP.NET(母版页,成员资格和登录,网站导航,主题等)的所有功能。不再需要使用FrontPage Server Extensions(FPSE)。

Web Site project model

网站项目模型

  • No project file (Based on file system).
  • 没有项目文件(基于文件系统)。

  • New compilation model.
  • 新的编译模型。

  • Dynamic compilation and working on pages without building entire siteon each page view.
  • 动态编译和处理页面而不在每个页面视图中构建整个站点。

  • Supports both IIS and the built-in ASP.NET Development Server.
  • 支持IIS和内置的ASP.NET开发服务器。

  • Each page has it's own assembly.
  • 每个页面都有自己的程序集。

  • Defferent code model.
  • 不同的代码模型。

#17


It is always depends on the requirement of your client. ASP.NET just includes flexible features that the user needs for security and easy maintenance of your application.

它始终取决于您的客户的要求。 ASP.NET只包含用户安全性和易于维护应用程序所需的灵活功能。

You can think of a Web application as a binary file that runs inside the ASP.NET framework. And Web sites as a static webpage that you can review and easily deploy source code to.

您可以将Web应用程序视为在ASP.NET框架内运行的二进制文件。而网站作为静态网页,您可以查看并轻松部署源代码。

But the advantage and disadvantages of these two ASP.NET technologies come what is good.

但是这两种ASP.NET技术的优点和缺点都是有益的。

#18


Websites - No solution file will be created. If we want to create websites no need for visual studio.

网站 - 不会创建解决方案文件。如果我们想创建不需要Visual Studio的网站。

Web Application - A solution file will be created. If we want to create web application should need the visual studio. It will create a single .dll file in bin folder.

Web应用程序 - 将创建解决方案文件。如果我们要创建Web应用程序,则需要Visual Studio。它将在bin文件夹中创建一个.dll文件。

#19


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.

在Web应用程序项目中,Visual Studio需要用于页面和用户控件的其他.designer文件。网站项目不需要这种开销。标记本身被解释为设计。

#20


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.

WebSite:它会自动生成app_code文件夹,如果您在服务器上发布它,之后如果您在任何特定文件或页面中进行某些更改,则不必编译所有文件。

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.

Web应用程序它自动生成解决方案文件,哪个网站不生成,如果您更改一个文件,则必须编译完整项目以反映其更改。

#21


In a web application you can create the layers of your project's functionality and can create inter-dependencies between them by dividing it into many projects, but you can never do this on a website.

在Web应用程序中,您可以创建项目功能的各个层,并通过将它们划分为多个项目来创建它们之间的相互依赖关系,但您永远不能在网站上执行此操作。

#22


Definitely web application, single DLL file and easy to maintain. But a website is more flexible; you can edit the aspx file on the go.

绝对是Web应用程序,单个DLL文件,易于维护。但是网站更灵活;你可以随时编辑aspx文件。

#23


Web applications require more memory, presumably because you have no choice but to compile into a single assembly. I just converted a large legacy site to a web application and have issues with running out of memory, both at compile time with the error message as below :

Web应用程序需要更多内存,大概是因为您别无选择只能编译成单个程序集。我刚刚将一个大型遗留站点转换为Web应用程序,并且在编译时出现内存不足的问题,并显示如下错误消息:

Unexpected error writing metadata to file '' -- Not enough storage is available to complete this operation. 

error, and at runtime with this error message as below :

错误,并在运行时出现此错误消息,如下所示:

Exception information:     Exception type: HttpException     Exception message: Exception of type 'System.OutOfMemoryException' was thrown.   at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()

My recommendation for converting larger sites on memory-constrained legacy hardware is, to choose the option to revert back to the web site model. Even after an initial success problem might creep up later.

我建议在内存受限的旧硬件上转换大型网站,选择恢复为网站模型的选项。即使在最初的成功问题可能会在以后蔓延。

#24


ASP.NET网站或ASP.NET Web应用程序?

Here Web Supportive Application is an example of website.Website and Web Application both can be dynamic/static its depends upon requirements, here is an example to understand working of website's and web application.

这里Web支持应用程序是一个网站的例子。网站和Web应用程序都可以是动态/静态的,它取决于要求,这里是一个了解网站和Web应用程序工作的例子。

#25


To summarize some of the answers above:

总结一下上面的一些答案:

Flexibility, can you can make live changes to a web page?

灵活性,您可以对网页进行实时更改吗?

Web Site: Possible. Pro: short term benefits. Con: long term risk of project chaos.

网站:可能。亲:短期利益。骗局:项目混乱的长期风险。

Web App: Con: not possible. Edit a page, archive the changes to source control, then build and deploy the entire site. Pro: maintain a quality project.

Web App:Con:不可能。编辑页面,将更改存档到源控件,然后构建和部署整个站点。亲:保持优质项目。

Development issues

Web Site: Simple project structure without a .csproj file.Two .aspx pages may have the same class name without conflicts. Random project directory name leading to build errors like why .net framework conflicts with its own generated file and why .net framework conflicts with its own generated file. Pro: Simple (simplistic). Con: erratic.

网站:没有.csproj文件的简单项目结构。两个.aspx页面可能具有相同的类名而没有冲突。随机项目目录名称导致构建错误,例如.net框架与其自己生成的文件冲突的原因以及.net框架与其自己生成的文件冲突的原因。亲:简单(简单)。骗局:不稳定。

Web App: Project structure similar to WebForms project, with a .csproj file. Class names of asp pages must be unique. Pro: Simple (smart). Con: none, because a web app is still simple.

Web App:类似于WebForms项目的项目结构,带有.csproj文件。 asp页面的类名必须是唯一的。亲:简单(聪明)。骗局:没有,因为网络应用仍然很简单。