简体   繁体   English

ASP.NET 网站还是 ASP.NET Web 应用程序?

[英]ASP.NET Web Site or ASP.NET Web Application?

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 网站。

What is the difference between ASP.NET Web Application and ASP.NET Web Site? ASP.NET Web 应用程序和 ASP.NET 网站有什么区别? Why would I choose one over other?为什么我会选择其中之一?

Is the answer different based on which version of Visual Studio I am using?答案是否因我使用的 Visual Studio 版本而异?

Website:网站:

The Web Site project is compiled on the fly.网站项目是即时编译的。 You end up with a lot more DLL files, which can be a pain.你最终会得到更多的 DLL 文件,这可能会很痛苦。 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.如果 Visual Studio 没有被告知不断重复使用相同的名称,它会一直为页面生成的 DLL 文件提供新名称。 That can lead to having several close copies of DLL files containing the same class name, which will generate plenty of errors.这可能导致多个包含相同类名的 DLL 文件的紧密副本,这将产生大量错误。 The Web Site project was introduced with Visual Studio 2005, but it has turned out not to be popular. Web Site 项目是在 Visual Studio 2005 中引入的,但结果证明它并不流行。

Web Application: Web应用程序:

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 similarly to the Web projects that shipped with Visual Studio 2003. It will compile the application into a single DLL file at build time. Web 应用程序项目是作为加载项创建的,现在作为 Visual Studio 2005 的 SP 1 的一部分存在。主要区别在于 Web 应用程序项目的工作方式与 Visual Studio 2003 附带的 Web 项目类似。它将在构建时将应用程序编译为单个 DLL 文件。 To update the project, it must be recompiled and the DLL file published for changes to occur.要更新项目,必须重新编译它并发布 DLL 文件以进行更改。

Another nice feature of the Web Application project is it's much easier to exclude files from the project view. Web Application 项目的另一个不错的特性是从项目视图中排除文件要容易得多。 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.在 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.文章ASP.NET 2.0 - 网站与 Web 应用程序项目也给出了为什么使用一个而不是另一个的原因。 Here is an excerpt of it:这是它的摘录:

  • You need to migrate large Visual Studio .NET 2003 applications to VS 2005?您需要将大型 Visual Studio .NET 2003 应用程序迁移到 VS 2005 吗? use the Web Application project.使用 Web 应用程序项目。
  • You want to open and edit any directory as a Web project without creating a project file?您想在不创建项目文件的情况下将任何目录作为 Web 项目打开和编辑? use Web Site project.使用网站项目。
  • 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?您需要使用多个 Web 项目构建一个 Web 应用程序吗? use the Web Application project.使用 Web 应用程序项目。
  • You want to generate one assembly for each page?您想为每一页生成一个程序集吗? use the 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. Web 应用程序项目与网站项目(MSDN) 解释了网站和 Web 应用程序项目之间的差异。 Also, it discusses the configuration to be made in Visual Studio.此外,它还讨论了要在 Visual Studio 中进行的配置。

Web Site is what you deploy to an ASP.NET web server such as IIS.网站是您部署到 ASP.NET Web 服务器(如 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).网站中没有任何东西可以将您与 Visual Studio 联系起来(没有项目文件)。 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.网页(如.aspx、.ascx、.master)的代码生成和编译在运行时动态完成,框架检测到这些文件的更改并自动重新编译。 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.您可以将要在页面之间共享的代码放在特殊的 App_Code 文件夹中,也可以预编译并将程序集放在 Bin 文件夹中。

Web Application is a special Visual Studio project. Web 应用程序是一个特殊的 Visual Studio 项目。 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.与网站的主要区别在于,当您构建项目时,所有代码文件都被编译成一个程序集,该程序集位于 bin 目录中。 You don't deploy code files to the web server.您不会将代码文件部署到 Web 服务器。 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 中有一个发布命令可将网站输出到指定位置。

App_Code vs Bin App_Code 与 Bin

Deploying shared code files is generally a bad idea, but that doesn't mean you have to choose Web Application.部署共享代码文件通常是一个坏主意,但这并不意味着您必须选择 Web 应用程序。 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 应用程序只是一种方便的方法。

CodeBehind代码隐藏

This topic is specific to .aspx and .ascx files.本主题特定于 .aspx 和 .ascx 文件。 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.在不使用代码隐藏文件的新应用程序框架(例如 ASP.NET MVC 和 ASP.NET 网页)中,此主题的相关性越来越低。

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.通过将所有代码文件编译到一个程序集中,包括 .aspx 页面和 .ascx 控件的代码隐藏文件,在 Web 应用程序中,您必须为每一个小的更改重新构建,并且您无法进行实时更改。 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.这在开发过程中可能是一个真正的痛苦,因为您必须不断重新构建才能看到更改,而 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.我并不是说部署代码文件总是一个好主意(特别是在共享代码文件的情况下),但代码隐藏文件应该只包含执行 UI 特定任务、连接事件处理程序等的代码。您的应用程序应该是分层以便重要的代码总是最终在 Bin 文件夹中。 If that is the case then deploying codebehind files shouldn't be considered harmful.如果是这种情况,那么部署代码隐藏文件不应被视为有害。

Another limitation of Web Applications is that you can only use the language of the project. Web 应用程序的另一个限制是您只能使用项目的语言。 In Web Sites you can have some pages in C#, some in VB, etc. No need for special Visual Studio support.在网站中,你可以有一些 C# 的页面,一些 VB 等等。不需要特殊的 Visual Studio 支持。 That's the beauty of the build provider extensibility.这就是构建提供程序可扩展性的美妙之处。

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.因为 Web 应用程序是 Visual Studio 项目,所以您可以获得网站中没有的一些功能。 For instance, you can use build events to perform a variety of tasks, eg minify and/or combine Javascript files.例如,您可以使用构建事件来执行各种任务,例如缩小和/或组合 Javascript 文件。

Another nice feature introduced in Visual Studio 2010 is Web.config transformation . Visual Studio 2010 中引入的另一个不错的功能是Web.config 转换 This is also not available in Web Sites.这在网站中也不可用。 Now works with Web Sites in VS 2013.现在适用于 VS 2013 中的网站。

Building a Web Application is faster than building a Web Site, specially for large sites.构建 Web 应用程序比构建 Web 站点更快,特别是对于大型站点。 This is mainly because Web Applications do not compile the markup code.这主要是因为 Web 应用程序不编译标记代码。 In MVC if you set MvcBuildViews to true then it compiles the markup code and you get error detection, which is very useful.在 MVC 中,如果您将 MvcBuildViews 设置为 true,那么它会编译标记代码并进行错误检测,这非常有用。 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).我发现自己打开和关闭了 MvcBuildViews(这需要卸载项目)。 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.如果您选择不这样做,那么构建解决方案的速度会非常快,并且您可以随时单击“网站”节点并选择“构建”(如果您进行了更改)。

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.如果您使用 IIS Express 作为开发服务器,则可以在网站中添加虚拟目录。 This option is not available in Web Applications.此选项在 Web 应用程序中不可用。

NuGet Package Restore does not work on Web Sites, you have to manually install packages listed on packages.config NuGet 包还原在网站上不起作用,您必须手动安装 packages.config 中列出的包Package Restore now works with Web Sites starting NuGet 2.7包还原现在适用于从 NuGet 2.7 开始的网站

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. Web 站点可以使用任何 HTML 工具进行工作,而无需拥有 developer studio,因为项目文件不需要更新等。当团队主要使用 developer studio 并且代码内容较多时,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.警告:我多年前写了这个答案,从那以后就没有使用过 Asp.net。 I expect things have now moved on.我希望事情现在已经有了进展。

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 (eg find usages, refactor) in Visual Studio will all take forever on any reasonably sized project. Visual Studio 中的静态类型查找功能(例如查找用法、重构)在任何规模合理的项目中都将永远存在。 For further information, see the Stack Overflow question Slow “Find All References” in Visual Studio .有关更多信息,请参阅Visual Studio 中的 Stack Overflow 问题慢“查找所有引用”

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 应用程序,因为它会导致痛苦、理智、效率低下的 carbuncle 网站项目类型。

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, eg:顺便说一句:关于该主题有一些类似的问题,例如:

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.这听起来可能有点明显,但我认为这是一种误解,因为 Visual Studio 2005 最初只随网站一起提供。 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.但是,如果它确实是一个具有多个用户添加和更新数据的不同模块的 Web 应用程序,那么您最好使用 Web 应用程序。

The biggest pro of the website model is that anything in the app_code section is dynamically compiled.网站模型的最大app_codeapp_code部分中的任何内容都是动态编译的。 You can make C# file updates without a full redeploy.您无需完全重新部署即可更新 C# 文件。 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下的任何内容的特定 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.如果您正在进行 n 层开发,我强烈推荐 Web 应用程序模型。 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 in:更详细的分析可以在:

From the MCTS self paced training kit exam 70-515 book:来自 MCTS 自定进度培训套件考试 70-515 书:

With web application (project),使用网络应用程序(项目),

  1. You can create an MVC application.您可以创建一个 MVC 应用程序。
  2. Visual Studio stores the list of files in a project file (.csproj or .vbproj), rather than relying on the folder structure. Visual Studio 将文件列表存储在项目文件(.csproj 或 .vbproj)中,而不是依赖于文件夹结构。
  3. You cannot mix Visual Basic and C#.不能混合使用 Visual Basic 和 C#。
  4. You cannot edit code without stopping a debugging session.您不能在不停止调试会话的情况下编辑代码。
  5. You can establish dependencies between multiple web projects.您可以在多个 Web 项目之间建立依赖关系。
  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.如果不重新编译,您将无法在部署后编辑单个文件。

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 应用程序,其中程序集的部署受到更多控制并且对单元测试有更好的支持。

Compilation Firstly there is a difference in compilation. 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.在 Web 应用程序中你不能这样做,因为一切都是预编译的,你最终只有一个 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.另一方面,如果您不希望您的代码在服务器上可用,您应该选择 Web 应用程序。 This option is also better for Unit Testing because of one DLL file being created after publishing your website.此选项也更适合单元测试,因为在发布您的网站后会创建一个 DLL 文件。

Project structure There is also a difference in the structure of the project. Project structure也有所不同。 In Web Application you have a project file just like you had it in normal application.在 Web 应用程序中,您有一个项目文件,就像在普通应用程序中一样。 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.所有引用和设置都存储在 web.config 文件中。 @Page directive There is a different attribute in @Page directive for the file that contains class associated with this page. @Page directive有一个不同的属性,用于包含与此页面关联的类的文件。 In Web Application it is standard "CodeBehind", in Web Site you use "CodeFile".在 Web 应用程序中,它是标准的“CodeBehind”,在网站中,您使用“CodeFile”。 You can see this in the examples below:您可以在以下示例中看到这一点:

Web Application: Web应用程序:

<%@ 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.在 Web 应用程序中,命名空间只是项目的名称。 In Website there is default namespace ASP for dynamically compiled pages.在网站中有动态编译页面的默认命名空间 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).编辑并继续 - 在 Web 应用程序中,可以使用“编辑并继续”选项(要打开它,您必须转到“工具”菜单,单击“选项”,然后在“调试”中找到“编辑并继续”)。 This feature is not working in Web Site.ASP.NET MVCIf you want to develop web applications using此功能在 Web Site.ASP.NET MVC 中不起作用如果您想使用开发 Web 应用程序

ASP.NET MVC (Model View Controller) the best and default option is Web Application. ASP.NET MVC(模型视图控制器)的最佳和默认选项是 Web 应用程序。 Although it's possible to use MVC in Web Site it's not recommended.尽管可以在网站中使用 MVC,但不推荐使用。

Summary - The most important difference between ASP.NET Web Application and Web Site is compilation.总结 - ASP.NET Web 应用程序和网站之间最重要的区别是编译。 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.但是如果您正在做一个较小的项目,您也可以使用 Web 应用程序。

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 project dependencies between.在一个保护伞下拥有多个项目并在它们之间建立项目依赖关系。 Eg for PCS we can have following within web application-例如,对于 PCS,我们可以在 Web 应用程序中进行以下操作 -

    • 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 are associated with ASP.NET pages对与 ASP.NET 页面关联的类文件中的代码运行单元测试

  3. To refer to the classes those are associated with pages and user controls from standalone classes从独立类引用与页面和用户控件关联的类
  4. To create a single assembly for the entire site为整个站点创建单个程序集
  5. Control over the assembly name and version number that is generated for the site控制为站点生成的程序集名称和版本号
  6. To avoid putting source code on a production server.避免将源代码放在生产服务器上。 (You can avoid deploying source code to the IIS server. In some scenarios, such as shared hosting environments, you might be concerned about unauthorized access to source code on the IIS server. (For a web site project, you can avoid this risk by pre-compiling on a development computer and deploying the generated assemblies instead of the source code. However, in that case you lose some of the benefits of easy site updates.) (您可以避免将源代码部署到 IIS 服务器。在某些情况下,例如共享主机环境,您可能会担心未经授权访问 IIS 服务器上的源代码。(对于网站项目,您可以通过以下方式避免这种风险)在开发计算机上预编译并部署生成的程序集而不是源代码。但是,在这种情况下,您将失去一些简单站点更新的好处。)
  7. Performance Issue with Website(The first 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 an IIS server that is short on memory, including the entire site in a single assembly might use more memory than would be required for multiple assemblies.)网站的性能问题(对网站的第一个请求可能需要编译网站,这可能会导致延迟。如果网站在内存不足的 IIS 服务器上运行,包括整个网站在一个单个程序集可能使用比多个程序集所需的更多内存。)

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 中消除。

Applications are usually compiled before deployment where as the website makes use of the app_code directory.应用程序通常在部署之前编译,因为网站使用 app_code 目录。 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.这意味着您可以在网站上动态添加/更改代码。

The advantage of an app is that there is no re-compiling and so initial start up times will be faster.应用程序的优点是无需重新编译,因此初始启动时间会更快。

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).顺便说一句,不要被标题弄糊涂了,视频的很大一部分解释了网站项目和 Web 应用程序项目之间的区别,以及为什么 Microsoft 在 Visual Studio 2005 中重新引入了 Web 应用程序项目(您可能已经知道,它最初仅随网站项目一起提供,然后在 SP1 中添加了 Web 应用程序项目)。 A great video I highly recommend for anyone who wants to know the difference.我强烈推荐给想要了解其中区别的任何人的精彩视频。

A "web site" has its code in a special App_Code directory and it's compiled into several DLLs (assemblies) at runtime.一个“网站”在一个特殊的 App_Code 目录中有它的代码,它在运行时被编译成几个 DLL(程序集)。 A "web application" is precompiled into one single DLL. “Web 应用程序”被预编译为一个单独的 DLL。

Website and Project>>website are two different methods of creating ASP.NET application using visual studio.网站和项目>>网站是使用 Visual Studio 创建 ASP.NET 应用程序的两种不同方法。 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.但是,如果您正在创建需要更长时间的网站,请选择项目环境。

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.您可以将Web 应用程序视为在 ASP.NET 框架内运行的二进制文件。 And Web sites as a static webpage that you can review and easily deploy source code to.网站作为静态网页,您可以查看并轻松部署源代码。

But the advantage and disadvantages of these two ASP.NET technologies come what is good.但这两种 ASP.NET 技术的优缺点各有千秋。

Web Application project model Web 应用程序项目模型

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

Web Site project model网站项目模型

  • No project file (Based on file system).没有项目文件(基于文件系统)。
  • New compilation model.新的编译模型。
  • Dynamic compilation and working on pages without building entire site on 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.不同的代码模型。

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. Web 应用程序 - 将创建解决方案文件。 If we want to create web application should need the visual studio.如果我们要创建 Web 应用程序应该需要 Visual Studio。 It will create a single .dll file in bin folder.它将在 bin 文件夹中创建一个.dll文件。

In Web Application Projects, Visual Studio needs additional .designer files for pages and user controls.在 Web 应用程序项目中,Visual Studio 需要用于页面和用户控件的其他 .designer 文件。 Web Site Projects do not require this overhead.网站项目不需要这种开销。 The markup itself is interpreted as the design.标记本身被解释为设计。

Definitely web application, single DLL file and easy to maintain.绝对是 Web 应用程序,单个 DLL 文件且易于维护。 But a website is more flexible;但是网站更灵活; you can edit the aspx file on the go.您可以随时随地编辑 aspx 文件。

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.网站:它会自动生成 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 应用程序它会自动生成解决方案文件,而网站不会生成该文件,如果您更改了一个文件,则必须编译整个项目以反映其更改。

Web applications require more memory, presumably because you have no choice but to compile into a single assembly. Web 应用程序需要更多内存,大概是因为您别无选择,只能编译为单个程序集。 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 应用程序,并且在编译时遇到内存不足的问题,错误消息如下:

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.即使在最初的成功之后,问题也可能会在以后蔓延。

在 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 应用程序的工作。

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.优点:保持高质量的项目。

Development issues发展问题

Web Site : Simple project structure without a .csproj file.Two .aspx pages may have the same class name without conflicts.网站:没有 .csproj 文件的简单项目结构。两个 .aspx 页面可能具有相同的类名而不会发生冲突。 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 .导致构建错误的随机项目目录名称,例如为什么 .net 框架与其自己生成的文件冲突以及为什么 .net 框架与其自己生成的文件冲突 Pro: Simple (simplistic).优点:简单(简单化)。 Con: erratic.缺点:不稳定。

Web App : Project structure similar to WebForms project, with a .csproj file. Web App :项目结构类似于 WebForms 项目,带有一个 .csproj 文件。 Class names of asp pages must be unique. asp 页面的类名必须是唯一的。 Pro: Simple (smart).优点:简单(智能)。 Con: none, because a web app is still simple.缺点:无,因为网络应用程序仍然很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM