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

发布于 2024-07-12 02:44:31 字数 192 浏览 13 评论 0原文

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

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

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(23

挖个坑埋了你 2024-07-19 02:44:31

网站:

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

如果 Visual Studio 没有被告知不断重复使用相同的名称,它将始终为页面生成的 DLL 文件提供新名称。 这可能会导致 DLL 文件有多个包含相同类名的紧密副本,
这会产生大量错误。 该网站项目是随 Visual Studio 2005 一起引入的,但结果并不流行。

Web 应用程序:

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

Web 应用程序的另一个不错的功能
项目的优点是从项目视图中排除文件要容易得多。 在里面
网站项目,您排除的每个文件都用排除的名称重命名
文件名中的关键字。 在Web应用程序项目中,该项目只是
跟踪要从项目视图中包含/排除的文件,而无需
重命名它们,使事情变得更加整洁。

参考

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

  • 您需要将大型 Visual Studio .NET 2003 应用程序迁移到 VS
    2005年? 使用网络应用程序项目。
  • 您想要将任何目录作为 Web 项目打开和编辑,而无需
    创建项目文件? 使用网站
    项目。
  • 您需要在编译期间添加预构建和后构建步骤吗?
    使用网络应用程序项目。
  • 您需要使用多个 Web 构建一个 Web 应用程序
    项目? 使用网络应用程序项目。
  • 您想为每一页生成一个程序集吗? 使用网站项目。
  • 您更喜欢动态编译并在不构建的情况下处理页面
    每个页面浏览整个网站? 使用网络
    网站项目。
  • 您更喜欢单页代码模型而不是代码隐藏模型? 使用网站
    项目。

Web 应用程序项目与网站项目 (MSDN) 解释了网站和 Web 应用程序项目之间的差异。 此外,它还讨论了在 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. It also gives problems when you have pages or controls in one directory that need to reference pages and controls in another directory since the other directory may not be compiled into the code yet. Another problem can be in publishing.

If Visual Studio isn't told to re-use the same names constantly, it will come up with new names for the DLL files generated by pages all the time. That can lead to having several close copies of DLL files containing the same class name,
which will generate plenty of errors. The Web Site project was introduced with Visual Studio 2005, but it has turned out not to be popular.

Web Application:

The Web Application Project was created as an add-in and now exists as part
of SP 1 for Visual Studio 2005. The main differences are the Web Application Project
was designed to work similarly to the Web projects that shipped with Visual Studio 2003. It will compile the application into a single DLL file at build
time. To update the project, it must be recompiled and the DLL file
published for changes to occur.

Another nice feature of the Web Application
project is it's much easier to exclude files from the project view. In the
Web Site project, each file that you exclude is renamed with an excluded
keyword in the filename. In the Web Application Project, the project just
keeps track of which files to include/exclude from the project view without
renaming them, making things much tidier.

Reference

The article ASP.NET 2.0 - Web Site vs Web Application project also gives reasons on why to use one and not the other. Here is an excerpt of it:

  • You need to migrate large Visual Studio .NET 2003 applications to VS
    2005? use the Web Application project.
  • You want to open and edit any directory as a Web project without
    creating a project file? use Web Site
    project.
  • You need to add pre-build and post-build steps during compilation?
    use Web Application project.
  • You need to build a Web application using multiple Web
    projects? use the Web Application project.
  • 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. Also, it discusses the configuration to be made in Visual Studio.

Saygoodbye 2024-07-19 02:44:31

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

Web应用程序是一个特殊的Visual Studio项目。 与网站的主要区别在于,当您构建项目时,所有代码文件都被编译到单个程序集中,该程序集放置在 bin 目录中。 您无需将代码文件部署到 Web 服务器。您可以将共享代码文件放在任何地方,而不是使用专门的文件夹,就像在类库中一样。 由于 Web 应用程序包含不需要部署的文件,例如项目和代码文件,因此有一个发布 命令将网站输出到指定位置。

App_Code 与 Bin

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

代码隐藏

本主题特定于 .aspx 和 .ascx 文件。 本主题与新的应用程序框架(例如不使用代码隐藏文件的 ASP.NET MVC 和 ASP.NET 网页)的相关性逐渐减弱。

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

让运行时管理代码隐藏程序集对您来说工作量更少,因为您无需担心为页面/控件提供唯一名称,或将它们组织到不同的命名空间中。

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

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

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

Visual Studio

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

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

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

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

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

NuGet Package Restore 不适用于网站,您必须手动安装packages.config 上列出的包 Package Restore 现在适用于网站 启动 NuGet 2.7

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

纵性 2024-07-19 02:44:31

网站 = 当网站由图形设计师创建且程序员仅编辑一两个页面时使用

Web 应用程序 = 当应用程序由程序员和图形设计师创建时使用仅编辑一页或两页/图像。

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

(一些编码错误是在编译时在 Web 应用程序中发现的,但直到运行时才在网站中发现。)

警告: 我在很多年前写过这个答案,并且没有使用过 Asp.net自从。 我预计事情现在已经有所进展。

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

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

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

风月客 2024-07-19 02:44:31

除非您对动态编译项目有特定需求,否则不要使用网站项目

为什么? 因为当你试图改变或理解你的项目时,网站项目会让你陷入困境。 Visual Studio 中的静态类型查找功能(例如查找用法、重构)在任何大小合理的项目上都将花费很长时间。 有关详细信息,请参阅 StackOverflow 问题缓慢“查找所有引用” ”在 Visual Studio 中。

我真的不明白为什么他们放弃 Visual Studio 2005 中的 Web 应用程序来处理令人痛苦、消耗理智、生产力高的网站项目类型。

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.

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.

眼前雾蒙蒙 2024-07-19 02:44:31

这听起来可能有点明显,但我认为这是被误解的,因为 Visual Studio 2005 最初只随网站一起提供。 如果您的项目涉及的网站相当有限并且没有太多逻辑或物理分离,那么该网站就很好。 但是,如果它确实是一个具有不同模块的 Web 应用程序,其中许多用户添加和更新数据,那么您最好使用该 Web 应用程序。

网站模型的最大优点是 app_code 部分中的任何内容都是动态编译的。 您可以更新 C# 文件,而无需完全重新部署。 然而,这是付出巨大牺牲的。 很多事情都在幕后发生,难以控制。 命名空间很难控制,并且默认情况下,对于 app_code 下的任何内容,特定 DLL 的使用都会被排除在外,因为所有内容都是动态编译的。

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

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

更详细的分析可以在:

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.

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.

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

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.

More detailed analysis can be found in:

樱&纷飞 2024-07-19 02:44:31

来自 MCTS 自定进度培训套件考试 70-515 书中:

通过网络应用程序(项目),

  1. 您可以创建 MVC 应用程序。
  2. Visual Studio 将文件列表存储在项目文件(.csproj 或 .vbproj)中,而不是依赖于文件夹结构。
  3. 不能混合使用 Visual Basic 和 C#。
  4. 如果不停止调试会话,您就无法编辑代码。
  5. 您可以在多个网络项目之间建立依赖关系。
  6. 您必须在部署之前编译应用程序,这样如果某个页面无法编译,您就无法测试另一个页面。
  7. 您不必将源代码存储在服务器上。
  8. 您可以控制程序集名称和版本。
  9. 部署后,如果不重新编译,则无法编辑单个文件。

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

With web application (project),

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

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

一个以内容为导向的网站的内容会经常变化,而网站更适合这一点。

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

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.

枕花眠 2024-07-19 02:44:31

编译 首先,编译方面存在差异。 网站不是在服务器上预编译的,而是在文件上编译的。 可能是
这是一个优势,因为当您想要更改网络中的某些内容时
您可以在网站上从服务器下载特定文件,更改它并
将此文件上传回服务器,一切都会正常工作。 在网络中
应用程序你不能这样做,因为一切都是预编译的并且
你最终只得到一个 dll。 当您更改一个文件中的某些内容时
您的项目必须再次重新编译所有内容。 所以如果你愿意
希望能够更改服务器网站上的某些文件
为您提供更好的解决方案。 它还允许许多开发人员在同一个项目上工作
网站。 另一方面,如果您不希望您的代码成为
在服务器上可用,您应该选择 Web 应用程序。 这
该选项也更适合单元测试,因为一个 DLL 文件被
发布您的网站后创建。

项目结构

项目的结构也有区别。 在Web应用程序中,您有一个项目文件,就像在普通应用程序中一样。 在网站中,没有任何传统的项目文件; 你所拥有的只是一个解决方案文件。 所有引用和设置都存储在web.config 文件中。

@Page 指令

对于包含与此页面关联的类的文件,@Page 指令中有一个不同的属性。 在Web应用程序中,它是标准的“CodeBehind”,在网站中您使用“CodeFile”。 您可以在下面的示例中看到这一点:

Web 应用程序:

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

网站:

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

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

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

ASP.NET MVC(模型视图控制器)最好的默认选项是
Web应用程序。 尽管可以在网站中使用 MVC,但
不推荐。

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

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.

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 a normal application. In Web Site, there isn't any traditional project file; all you have is a solution file. All references and settings are stored in the web.config file.

@Page directive

There is a different attribute in the @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 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.

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

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.

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.

嗫嚅 2024-07-19 02:44:31

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

Visual Studio 2008 中消除了两者之间的区别。

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

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

叹沉浮 2024-07-19 02:44:31

我建议您观看视频Web 应用程序项目和视频 ASP.NET 网站上的 Web 部署项目 非常详细地解释了其中的差异,对我很有帮助。

顺便说一句,不要被标题搞糊涂了,视频的很大一部分解释了网站项目和 Web 应用程序项目之间的区别,以及为什么 Microsoft 在 Visual Studio 2005 中重新引入了 Web 应用程序项目(您可能已经知道,它最初仅附带网站项目,然后在 SP1 中添加了 Web 应用程序项目)。 我强烈推荐给所有想了解其中区别的人。

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.

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.

梦里梦着梦中梦 2024-07-19 02:44:31

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

应用程序的优点是无需重新编译,因此初始启动时间会更快。

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.

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

入画浅相思 2024-07-19 02:44:31

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

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.

倾听心声的旋律 2024-07-19 02:44:31

网站和项目>>网站是使用 Visual Studio 创建 ASP.NET 应用程序的两种不同方法。
一种是无项目的,另一种是项目环境。 区别在于

  1. 解决方案文件存储在与项目环境中的根目录相同的目录中。
  2. 在项目环境中部署之前需要删除解决方案和项目文件。
  3. 完整的根目录部署在无项目环境中。

使用这两种方法没有太大的基本区别。 但如果您要创建需要较长时间的网站,请选择项目环境。

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

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

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

陌伤浅笑 2024-07-19 02:44:31

Web 应用程序项目模型

  • 提供与 Visual Studio .NET Web 相同的 Web 项目语义
    项目。 有一个项目文件(基于项目文件的结构)。
    构建模型 - 项目中的所有代码都编译成一个
    集会。 同时支持 IIS 和内置 ASP.NET 开发
    服务器。 支持 Visual Studio 2005 的所有功能(重构、
    泛型等)和 ASP.NET(母版页、成员资格和登录,
    站点导航、主题等)。 使用 FrontPage 服务器扩展
    (FPSE) 不再是必需的。

网站项目模型

  • 无项目文件(基于文件系统)。
  • 新的编译模型。
  • 动态编译和在页面上工作,无需构建整个网站
    在每个页面视图上。
  • 支持 IIS 和内置 ASP.NET 开发服务器。
  • 每个页面都有它自己的程序集。
  • 不同的代码模型。

Web Application project model

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

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.
  • Each page has it's own assembly.
  • Defferent code model.
趁年轻赶紧闹 2024-07-19 02:44:31

这始终取决于客户的要求。 ASP.NET 仅包含用户需要的灵活功能,以确保应用程序的安全性和易于维护。

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

但这两种ASP.NET技术各有利弊。

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.

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.

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

独﹏钓一江月 2024-07-19 02:44:31

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

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.

单挑你×的.吻 2024-07-19 02:44:31

网站:它会自动生成app_code文件夹,如果您将其发布到服务器上,之后如果您在任何特定文件或页面中进行一些更改,则无需编译所有文件。

Web 应用程序它会自动生成解决方案文件,而网站不会生成该文件,如果您在一个文件中进行更改,则必须编译整个项目才能反映其更改。

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

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

神回复 2024-07-19 02:44:31

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

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

Websites - No solution file will be created. If we want to create websites no need for 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.

尹雨沫 2024-07-19 02:44:31

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

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.

自此以后,行同陌路 2024-07-19 02:44:31

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

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.

_失温 2024-07-19 02:44:31

Web 应用程序需要更多内存,大概是因为您别无选择,只能编译成单个程序集。 我刚刚将一个大型旧网站转换为 Web 应用程序,但遇到了内存不足的问题,在编译时,错误消息如下:

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

在运行时,错误消息如下:

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

我对在内存上转换较大网站的建议 -受旧硬件的限制,选择恢复到网站模型的选项。 即使取得了最初的成功,问题也可能会在以后逐渐出现。

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

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

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, problems might creep up later.

韬韬不绝 2024-07-19 02:44:31

总结一下之前的一些答案:

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

网站:可能。 优点:短期利益。 缺点:项目混乱的长期风险。

Web 应用程序:缺点:不可能。 编辑页面,将更改存档到源代码管理,然后构建和部署整个站点。 优点:保持高质量的项目。

开发问题

网站:没有 .csproj 的简单项目结构
没有冲突。 随机项目目录名称会导致构建错误,例如 Why does the .NET Framework 与其自己生成的文件冲突?为什么.NET框架与其自己生成的文件冲突?。 优点:简单(简单化)。 缺点:不稳定。

Web 应用程序:项目结构类似于 WebForms 项目,带有 .csproj 文件。 asp 页面的类名必须是唯一的。 优点:简单(智能)。 缺点:没有,因为 Web 应用程序仍然很简单。

To summarize some of the previous answers:

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 Application: 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
without conflicts. Random project directory name leading to build errors like Why does the .NET framework conflict with its own generated file? and Why does the .NET framework conflict with its own generated file?. Pro: Simple (simplistic). Con: erratic.

Web Application: 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 application is still simple.

往事风中埋 2024-07-19 02:44:31

这里是一个 Web 支持应用程序。这是一个网站示例。

这是一个 Web 支持应用程序。 这是一个网站的示例。

网站和 Web 应用程序都可以是动态/静态的。 这取决于要求,下面是一个了解网站和 Web 应用程序工作原理的示例。

Here is a Web Supportive Application. It is an example of a website.

Here is a Web Supportive Application. It is an example of a website.

A Website and Web application both can be dynamic/static. It depends upon requirements, and here is an example to understand the working of websites and web applications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文