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.
当我开始新的ASP。NET项目在Visual Studio中,我可以创建一个ASP。NET Web应用程序或者我可以创建一个ASP。网的网站。
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。网的网站吗?我为什么要选择一个呢?
Is the answer different based on which version of Visual Studio I am using?
答案是否与我所使用的Visual Studio的版本不同?
25 个解决方案
#1
497
Website:
网站:
The Web Site project is compiled on the fly. You end up with a lot more DLL files, which can be a pain. It also gives problems when you have pages or controls in one directory that need to reference pages and controls in another directory since the other directory may not be compiled into code yet. Another problem can be in publishing.
这个网站项目是动态编译的。你最终会得到更多的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文件的关闭副本,这将产生大量错误。这个网站项目是在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 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.
Web应用程序项目是作为一个插件创建的,现在作为Visual Studio 2005的sp1的一部分而存在。主要的不同之处在于,Web应用程序设计的工作原理与Visual Studio 2003发布的Web项目类似。它将在构建时将应用程序编译成一个DLL文件。为了更新项目,必须重新编译它,并发布用于更改的DLL文件。
Another nice feature of the Web Application project is it's much easer to exclude files from the project view. In the Web Site project, each file that you exclude is renamed with an exclude keyword in the filename. In the Web Application Project, the project just keeps track of which files to include/exclude from the project view without renaming them, making things much tidier.
Web应用程序项目的另一个好特性是,从项目视图中排除文件更容易。在Web站点项目中,您排除的每个文件都在filename中以排除关键字重命名。在Web应用程序项目中,项目只是跟踪哪些文件要包含/排除在项目视图中,而不需要重新命名它们,使事情变得更加整洁。
参考
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站点vs 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 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
151
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联系在一起(没有项目文件)。代码生成和web页面的编译(例如.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中有一个发布命令,可以将一个Web站点输出到指定的位置。
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)中,这个主题越来越不相关。净MVC和ASP。不使用codebehind文件的网络页面。
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控件的codebehind文件,在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代码,执行特定的任务,应用程序绑定事件处理程序等。应分层,这样重要的代码总是最终在本文件夹中。如果是这样,那么部署代码后文件不应该被认为是有害的。
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应用程序的另一个限制是,只能使用项目的语言。在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。配置转换。这在Web站点中也是不可用的。现在在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应用程序不编译标记代码。在MVC中,如果您将MvcBuildViews设置为true,那么它将编译标记代码并得到错误检测,这非常有用。缺点是,每次构建解决方案时,它都会构建完整的站点,这可能会很慢且效率低下,特别是如果您没有编辑站点。我发现自己打开和关闭MvcBuildViews(需要一个项目卸载)。另一方面,如果您想要构建站点作为解决方案的一部分,您可以选择使用Web站点。如果您选择不这样做,那么构建解决方案是非常快的,并且您可以随时单击Web站点节点并选择Build,如果您已经做出了更改。
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应用程序项目中,您可以为常见任务添加额外的命令和对话框,比如“Add View”、“Go To View”、“Add Controller”等,这些都在MVC Web站点中是不可用的。
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站点中可以添加虚拟目录。此选项在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包恢复在Web站点上不起作用,您必须手动安装包中列出的包。现在,配置包恢复与Web站点开始使用NuGet 2.7。
#3
69
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时,Web应用程序是最好的,并且有很高的代码内容。
(Some coding errors are found in Web Applications at compile time that are not found in Web Sites until run time.)
(有些编码错误是在编译时在Web应用程序中发现的,这些错误在运行时没有出现在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
37
Unless you have a specific need for a dynamically compiled project, don't use a web site project.
除非您对动态编译的项目有特定的需求,否则不要使用web站点项目。
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
25
There is an article in MSDN which describes the differences:
MSDN上有一篇文章描述了这些差异:
Comparing Web Site Projects and Web Application Projects
比较Web站点项目和Web应用程序项目。
BTW: there are some similar questions about that topic, e.g:
顺便说一下,关于这个话题有一些类似的问题。
- Web Site vs. ASP.Net Web Application in Visual Studio note: was removed, no longer on SO
- 网站与ASP。Net Web应用程序在Visual Studio注释中:被删除,不再是这样。
- website or webapplication in.ASP.NET
- 网站或webapplication in.ASP.NET
#6
19
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应用程序,有许多用户添加和更新数据的不同模块,那么您最好使用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应用程序模型。如果您正在进行一个有限的web站点或快速而又脏的实现,那么web站点模型可能具有优势。
More detailed analysis can be found in:
更详细的分析可以在:
- Web Application Projects and Web Deployment Projects are here
- Web应用程序项目和Web部署项目在这里。
- Web Site or Web Application?
- Web站点还是Web应用程序?
#7
18
From the MCTS self paced training kit exam 70-515 book:
从MCTS自我速度训练试剂盒考试70-515本书:
With web application (project),
与web应用程序(项目),
- You can create an MVC application.
- 您可以创建一个MVC应用程序。
- 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),而不是依赖于文件夹结构。
- You cannot mix Visual Basic and C#.
- 您不能混合Visual Basic和c#。
- You cannot edit code without stopping a debugging session.
- 您不能在不停止调试会话的情况下编辑代码。
- You can establish dependencies between multiple web projects.
- 您可以在多个web项目之间建立依赖关系。
- You must compile the application before deployment, which prevents you from testing a page if another page will not compile.
- 您必须在部署前编译应用程序,如果另一个页面无法编译,则无法测试页面。
- You do not have to store the source code on the server.
- 您不必在服务器上存储源代码。
- You can control the assembly name and version.
- 您可以控制程序集名称和版本。
- You cannot edit individual files after deployment without recompiling.
- 您不能在部署后编辑单个文件,而无需重新编译。
#8
12
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应用程序中,你不能这样做,因为所有的东西都是预编译的,而你只能得到一个dll。当您在项目的一个文件中更改某个内容时,您必须重新编译所有内容。因此,如果您希望有可能更改服务器Web站点上的一些文件,这是更好的解决方案。它还允许许多开发人员在一个Web站点上工作。另一方面,如果您不希望您的代码在服务器上可用,您应该选择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站点中没有传统的项目文件,所有的都是解决方案文件。所有的引用和设置都存储在web中。配置文件。@Page指令对包含与此页面相关的类的文件的@Page指令有一个不同的属性。在Web应用程序中,它是标准的“后台代码”,在Web站点中使用“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应用程序名称空间中,只是项目的名称。在网站中有默认的名称空间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站点中不起作用。您想要使用的web应用程序的NET MVCIf。
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应用程序。尽管在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站点。但是如果你在做一个较小的项目,你也可以使用Web应用程序。
#9
12
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应用程序,在这个应用程序中,程序集的部署更受控制,并且对单元测试有更好的支持。
#10
10
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中,两者的区别已经消失了。
#11
9
Yes web application is much better than web sites, because Web applications give us freedom:
是的,web应用程序比web站点好得多,因为web应用程序给了我们*:
-
To have multiple projects under one umbrella and establish project dependencies between. E.g. for PCS we can have following within web application-
在一个伞下有多个项目,并建立项目依赖关系。例如,对于我们可以在web应用程序中使用的pc。
- 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
- 列表项
-
To run unit tests on code that is in the class files that are associated with ASP.NET pages
在与ASP相关联的类文件中运行单元测试。网络页面
- To refer to the classes those are associated with pages and user controls from standalone classes
- 要引用那些与页面相关的类和来自独立类的用户控件。
- To create a single assembly for the entire site
- 为整个站点创建单个程序集。
- Control over the assembly name and version number that is generated for the site
- 控制为站点生成的程序集名称和版本号。
- 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服务器上对源代码的未授权访问。(对于web站点项目,您可以通过在开发计算机上预编译并部署生成的程序集而不是源代码来避免这种风险。然而,在这种情况下,你会失去一些网站更新的好处。
- 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.)
- 对网站的性能问题(对网站的第一个请求可能需要对站点进行编译,这会导致延迟。如果web站点运行在内存不足的IIS服务器上,包括单个程序集中的整个站点,那么可能会使用比多个程序集所需的更多内存。
#12
8
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
7
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上观看视频Web应用程序项目和Web部署项目。NET网站,详细说明了差异,对我很有帮助。
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应用程序项目的区别,为什么微软在Visual studio 2005中重新将web应用程序项目(正如您可能已经知道的,它最初只是附带网站项目web应用程序项目被添加在SP1)。我强烈推荐给任何想知道这一区别的人。
#14
7
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.
一个“web站点”在一个特殊的App_Code目录中有它的代码,它在运行时被编译成几个dll(程序集)。一个“web应用程序”被预先编译成一个DLL。
#15
5
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
>>网站是创建ASP的两种不同的方法。NET应用程序使用visual studio。一个是项目,另一个是项目环境。差异是
- Solution file is stored in same directory as root directory in project environment.
- 解决方案文件存储在与项目环境中的根目录相同的目录中。
- Need to remove solution and project files before deploying in project environment.
- 在项目环境中部署之前需要删除解决方案和项目文件。
- 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.
使用两种方法都没有什么基本的区别。但如果你创建的网站需要更长的时间,选择项目环境。
#16
5
Web Application project model
Web应用程序项目模型
- Provides the same Web project semantics as Visual Studio .NET Web projects. 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. 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 Web项目相同的Web项目语义。有一个项目文件(基于项目文件的结构)。构建模型——项目中的所有代码都被编译成一个程序集。支持IIS和内置ASP。网络开发服务器。支持Visual Studio 2005(重构、泛型等)和ASP的所有特性。NET(主页、会员和登录、网站导航、主题等)。使用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。网络开发服务器。
- Each page has it's own assembly.
- 每个页面都有自己的程序集。
- Defferent code model.
- 不同的代码模型。
#17
5
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中运行的二进制文件。净框架。而Web站点作为一个静态页面,您可以查看并轻松地部署源代码。
But the advantage and disadvantages of these two ASP.NET technologies come what is good.
但是这两个ASP的优点和缺点。NET技术带来了好处。
#18
4
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
3
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文件用于页面和用户控件。Web站点项目不需要这种开销。标记本身被解释为设计。
#20
3
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应用程序自动生成解决方案文件,该文件不会生成,如果您在一个文件中更改,则需要编译整个项目以反映其更改。
#21
3
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
Web应用程序需要更多的内存,大概是因为您别无选择,只能编译成一个程序集。我只是将一个大型的遗留站点转换为一个web应用程序,并且在编译时与内存耗尽的问题。
Unexpected error writing metadata to file '' --
Not enough storage is available to complete this operation.
error and at runtime with this error:
错误和运行时的错误:
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 allow yourself the option to revert back to the web site model. Even after an initial success problems might creep up later.
我建议在内存受限的遗留硬件上转换更大的站点,以允许您自己返回到web站点模型。即使在最初的成功之后,问题可能会在以后慢慢出现。
#22
3
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应用程序中,您可以创建项目的功能层,并且可以通过将其划分为多个项目来创建它们之间的相互依赖关系,但是您不能在网站上这样做。
#23
3
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文件,易于维护。但网站更灵活;您可以在go上编辑aspx文件。
#24
#25
0
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. 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.
Web站点:没有.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应用程序:与WebForms项目类似的项目结构,带有.csproj文件。asp页面的类名必须是唯一的。正方观点:简单(聪明)。弊:没有,因为web应用程序仍然很简单。
#1
497
Website:
网站:
The Web Site project is compiled on the fly. You end up with a lot more DLL files, which can be a pain. It also gives problems when you have pages or controls in one directory that need to reference pages and controls in another directory since the other directory may not be compiled into code yet. Another problem can be in publishing.
这个网站项目是动态编译的。你最终会得到更多的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文件的关闭副本,这将产生大量错误。这个网站项目是在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 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.
Web应用程序项目是作为一个插件创建的,现在作为Visual Studio 2005的sp1的一部分而存在。主要的不同之处在于,Web应用程序设计的工作原理与Visual Studio 2003发布的Web项目类似。它将在构建时将应用程序编译成一个DLL文件。为了更新项目,必须重新编译它,并发布用于更改的DLL文件。
Another nice feature of the Web Application project is it's much easer to exclude files from the project view. In the Web Site project, each file that you exclude is renamed with an exclude keyword in the filename. In the Web Application Project, the project just keeps track of which files to include/exclude from the project view without renaming them, making things much tidier.
Web应用程序项目的另一个好特性是,从项目视图中排除文件更容易。在Web站点项目中,您排除的每个文件都在filename中以排除关键字重命名。在Web应用程序项目中,项目只是跟踪哪些文件要包含/排除在项目视图中,而不需要重新命名它们,使事情变得更加整洁。
参考
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站点vs 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 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
151
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联系在一起(没有项目文件)。代码生成和web页面的编译(例如.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中有一个发布命令,可以将一个Web站点输出到指定的位置。
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)中,这个主题越来越不相关。净MVC和ASP。不使用codebehind文件的网络页面。
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控件的codebehind文件,在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代码,执行特定的任务,应用程序绑定事件处理程序等。应分层,这样重要的代码总是最终在本文件夹中。如果是这样,那么部署代码后文件不应该被认为是有害的。
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应用程序的另一个限制是,只能使用项目的语言。在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。配置转换。这在Web站点中也是不可用的。现在在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应用程序不编译标记代码。在MVC中,如果您将MvcBuildViews设置为true,那么它将编译标记代码并得到错误检测,这非常有用。缺点是,每次构建解决方案时,它都会构建完整的站点,这可能会很慢且效率低下,特别是如果您没有编辑站点。我发现自己打开和关闭MvcBuildViews(需要一个项目卸载)。另一方面,如果您想要构建站点作为解决方案的一部分,您可以选择使用Web站点。如果您选择不这样做,那么构建解决方案是非常快的,并且您可以随时单击Web站点节点并选择Build,如果您已经做出了更改。
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应用程序项目中,您可以为常见任务添加额外的命令和对话框,比如“Add View”、“Go To View”、“Add Controller”等,这些都在MVC Web站点中是不可用的。
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站点中可以添加虚拟目录。此选项在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包恢复在Web站点上不起作用,您必须手动安装包中列出的包。现在,配置包恢复与Web站点开始使用NuGet 2.7。
#3
69
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时,Web应用程序是最好的,并且有很高的代码内容。
(Some coding errors are found in Web Applications at compile time that are not found in Web Sites until run time.)
(有些编码错误是在编译时在Web应用程序中发现的,这些错误在运行时没有出现在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
37
Unless you have a specific need for a dynamically compiled project, don't use a web site project.
除非您对动态编译的项目有特定的需求,否则不要使用web站点项目。
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
25
There is an article in MSDN which describes the differences:
MSDN上有一篇文章描述了这些差异:
Comparing Web Site Projects and Web Application Projects
比较Web站点项目和Web应用程序项目。
BTW: there are some similar questions about that topic, e.g:
顺便说一下,关于这个话题有一些类似的问题。
- Web Site vs. ASP.Net Web Application in Visual Studio note: was removed, no longer on SO
- 网站与ASP。Net Web应用程序在Visual Studio注释中:被删除,不再是这样。
- website or webapplication in.ASP.NET
- 网站或webapplication in.ASP.NET
#6
19
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应用程序,有许多用户添加和更新数据的不同模块,那么您最好使用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应用程序模型。如果您正在进行一个有限的web站点或快速而又脏的实现,那么web站点模型可能具有优势。
More detailed analysis can be found in:
更详细的分析可以在:
- Web Application Projects and Web Deployment Projects are here
- Web应用程序项目和Web部署项目在这里。
- Web Site or Web Application?
- Web站点还是Web应用程序?
#7
18
From the MCTS self paced training kit exam 70-515 book:
从MCTS自我速度训练试剂盒考试70-515本书:
With web application (project),
与web应用程序(项目),
- You can create an MVC application.
- 您可以创建一个MVC应用程序。
- 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),而不是依赖于文件夹结构。
- You cannot mix Visual Basic and C#.
- 您不能混合Visual Basic和c#。
- You cannot edit code without stopping a debugging session.
- 您不能在不停止调试会话的情况下编辑代码。
- You can establish dependencies between multiple web projects.
- 您可以在多个web项目之间建立依赖关系。
- You must compile the application before deployment, which prevents you from testing a page if another page will not compile.
- 您必须在部署前编译应用程序,如果另一个页面无法编译,则无法测试页面。
- You do not have to store the source code on the server.
- 您不必在服务器上存储源代码。
- You can control the assembly name and version.
- 您可以控制程序集名称和版本。
- You cannot edit individual files after deployment without recompiling.
- 您不能在部署后编辑单个文件,而无需重新编译。
#8
12
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应用程序中,你不能这样做,因为所有的东西都是预编译的,而你只能得到一个dll。当您在项目的一个文件中更改某个内容时,您必须重新编译所有内容。因此,如果您希望有可能更改服务器Web站点上的一些文件,这是更好的解决方案。它还允许许多开发人员在一个Web站点上工作。另一方面,如果您不希望您的代码在服务器上可用,您应该选择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站点中没有传统的项目文件,所有的都是解决方案文件。所有的引用和设置都存储在web中。配置文件。@Page指令对包含与此页面相关的类的文件的@Page指令有一个不同的属性。在Web应用程序中,它是标准的“后台代码”,在Web站点中使用“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应用程序名称空间中,只是项目的名称。在网站中有默认的名称空间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站点中不起作用。您想要使用的web应用程序的NET MVCIf。
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应用程序。尽管在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站点。但是如果你在做一个较小的项目,你也可以使用Web应用程序。
#9
12
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应用程序,在这个应用程序中,程序集的部署更受控制,并且对单元测试有更好的支持。
#10
10
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中,两者的区别已经消失了。
#11
9
Yes web application is much better than web sites, because Web applications give us freedom:
是的,web应用程序比web站点好得多,因为web应用程序给了我们*:
-
To have multiple projects under one umbrella and establish project dependencies between. E.g. for PCS we can have following within web application-
在一个伞下有多个项目,并建立项目依赖关系。例如,对于我们可以在web应用程序中使用的pc。
- 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
- 列表项
-
To run unit tests on code that is in the class files that are associated with ASP.NET pages
在与ASP相关联的类文件中运行单元测试。网络页面
- To refer to the classes those are associated with pages and user controls from standalone classes
- 要引用那些与页面相关的类和来自独立类的用户控件。
- To create a single assembly for the entire site
- 为整个站点创建单个程序集。
- Control over the assembly name and version number that is generated for the site
- 控制为站点生成的程序集名称和版本号。
- 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服务器上对源代码的未授权访问。(对于web站点项目,您可以通过在开发计算机上预编译并部署生成的程序集而不是源代码来避免这种风险。然而,在这种情况下,你会失去一些网站更新的好处。
- 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.)
- 对网站的性能问题(对网站的第一个请求可能需要对站点进行编译,这会导致延迟。如果web站点运行在内存不足的IIS服务器上,包括单个程序集中的整个站点,那么可能会使用比多个程序集所需的更多内存。
#12
8
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
7
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上观看视频Web应用程序项目和Web部署项目。NET网站,详细说明了差异,对我很有帮助。
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应用程序项目的区别,为什么微软在Visual studio 2005中重新将web应用程序项目(正如您可能已经知道的,它最初只是附带网站项目web应用程序项目被添加在SP1)。我强烈推荐给任何想知道这一区别的人。
#14
7
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.
一个“web站点”在一个特殊的App_Code目录中有它的代码,它在运行时被编译成几个dll(程序集)。一个“web应用程序”被预先编译成一个DLL。
#15
5
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
>>网站是创建ASP的两种不同的方法。NET应用程序使用visual studio。一个是项目,另一个是项目环境。差异是
- Solution file is stored in same directory as root directory in project environment.
- 解决方案文件存储在与项目环境中的根目录相同的目录中。
- Need to remove solution and project files before deploying in project environment.
- 在项目环境中部署之前需要删除解决方案和项目文件。
- 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.
使用两种方法都没有什么基本的区别。但如果你创建的网站需要更长的时间,选择项目环境。
#16
5
Web Application project model
Web应用程序项目模型
- Provides the same Web project semantics as Visual Studio .NET Web projects. 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. 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 Web项目相同的Web项目语义。有一个项目文件(基于项目文件的结构)。构建模型——项目中的所有代码都被编译成一个程序集。支持IIS和内置ASP。网络开发服务器。支持Visual Studio 2005(重构、泛型等)和ASP的所有特性。NET(主页、会员和登录、网站导航、主题等)。使用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。网络开发服务器。
- Each page has it's own assembly.
- 每个页面都有自己的程序集。
- Defferent code model.
- 不同的代码模型。
#17
5
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中运行的二进制文件。净框架。而Web站点作为一个静态页面,您可以查看并轻松地部署源代码。
But the advantage and disadvantages of these two ASP.NET technologies come what is good.
但是这两个ASP的优点和缺点。NET技术带来了好处。
#18
4
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
3
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文件用于页面和用户控件。Web站点项目不需要这种开销。标记本身被解释为设计。
#20
3
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应用程序自动生成解决方案文件,该文件不会生成,如果您在一个文件中更改,则需要编译整个项目以反映其更改。
#21
3
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
Web应用程序需要更多的内存,大概是因为您别无选择,只能编译成一个程序集。我只是将一个大型的遗留站点转换为一个web应用程序,并且在编译时与内存耗尽的问题。
Unexpected error writing metadata to file '' --
Not enough storage is available to complete this operation.
error and at runtime with this error:
错误和运行时的错误:
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 allow yourself the option to revert back to the web site model. Even after an initial success problems might creep up later.
我建议在内存受限的遗留硬件上转换更大的站点,以允许您自己返回到web站点模型。即使在最初的成功之后,问题可能会在以后慢慢出现。
#22
3
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应用程序中,您可以创建项目的功能层,并且可以通过将其划分为多个项目来创建它们之间的相互依赖关系,但是您不能在网站上这样做。
#23
3
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文件,易于维护。但网站更灵活;您可以在go上编辑aspx文件。
#24
2
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
0
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. 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.
Web站点:没有.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应用程序:与WebForms项目类似的项目结构,带有.csproj文件。asp页面的类名必须是唯一的。正方观点:简单(聪明)。弊:没有,因为web应用程序仍然很简单。