ASP.NET中的网站或Web应用程序

时间:2022-08-29 16:38:03

Which Visual Studio template should be used for a ASP.NET web site, the Web Site template or the Project | Web Application template?

哪个Visual Studio模板应该用于ASP.NET网站,Web站点模板或Project | Web应用程序模板?

7 个解决方案

#1


3  

you'd better read this: http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx in my opinion it depends on what you are developing

你最好读这个:http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx在我看来这取决于你正在开发什么

#2


3  

Both function and perform similarly, but still differ in following ways:

功能和功能都相似,但在以下方面仍然有所不同:

Web application:

  • We can't include C# and VB pages in single web application.
  • 我们不能在单个Web应用程序中包含C#和VB页面。

  • We can set up dependencies between multiple projects.
  • 我们可以在多个项目之间建立依赖关系。

  • Can not edit individual files after deployment without recompiling.
  • 无需重新编译即可在部署后编辑单个文件。

  • Right choice for enterprise environments where multiple developers work unitedly for creating, testing and deployment.
  • 适用于多个开发人员统一工作以进行创建,测试和部署的企业环境。

Web site:

  • Can mix VB and C# page in single website.
  • 可以在单个网站中混合使用VB和C#页面。

  • Can not establish dependencies.
  • 无法建立依赖关系。

  • Edit individual files after deployment.
  • 部署后编辑单个文件。

  • Right choice when one developer will responsible for creating and managing entire website.
  • 当一个开发人员负责创建和管理整个网站时,正确的选择。

#3


2  

Web application projects works more like a traditional VS project, which has a project file, is compiled in one step and so on.

Web应用程序项目更像传统的VS项目,它有一个项目文件,一步编译等等。

Web site projects works more like classic ASP or PHP-sites. There is no project file (references are stored in the solution file), and pages are recompiled dynamically on the server. The nice thing with web sites is that you can just ftp to the server and change a file in a text editor. You dont need VS. Some may hate that, though.

网站项目更像是传统的ASP或PHP站点。没有项目文件(引用存储在解决方案文件中),页面在服务器上动态重新编译。网站的好处是你只需要ftp到服务器并在文本编辑器中更改文件。你不需要VS.但有些人可能会讨厌这一点。

It probably depends on your background. If you are used to ASP or PHP style development, web site projects will seem more natural to you. If you have a traditional application developer background, web application projects will seem more natural.

这可能取决于你的背景。如果您习惯于ASP或PHP风格开发,那么网站项目对您来说似乎更自然。如果您拥有传统的应用程序开发人员背景,那么Web应用程序项目将更加自然。

#4


2  

If you're using Team Foundation Server for source control, you'll probably have to use a Web Application Project, as you need a .csproj file.

如果您使用Team Foundation Server进行源代码管理,则可能必须使用Web应用程序项目,因为您需要.csproj文件。

There are more details from Jeff Atwood himself: Web Site Projects vs. Web Application Projects

Jeff Atwood本人提供了更多详细信息:网站项目与Web应用程序项目

Web Site web projects are particularly painful in Team System due to the lack of a physical file that contains project information and metadata. For example, it's impossible to check in code analysis rules on Web Site projects, because the code analysis rules are stored entirely on the client!

由于缺少包含项目信息和元数据的物理文件,因此Web System Web项目在Team System中尤其痛苦。例如,无法检查Web站点项目上的代码分析规则,因为代码分析规则完全存储在客户端上!

#5


1  

I prefer a website. A website is a collection of files in a directory. It becomes more portable and deployable. A web application clouds the issue with a project file.

我更喜欢网站。网站是目录中文件的集合。它变得更加便携和可部署。 Web应用程序通过项目文件来解决问题。

#6


0  

Personally I use web application projects exclusively now. I actually converted a rather web site to a web application because of compilation times for the web site.

我个人现在专门使用Web应用程序项目。由于网站的编译时间,我实际上将一个相当网站转换为Web应用程序。

I also use pre-build events to move configuration specific configuration files around and pre-build and post-build events are not available in web sites.

我还使用预构建事件来移动配置特定的配置文件,并且在网站中不提供预构建和后构建事件。

#7


0  

In Visual Studio 2015, I've come to somewhat prefer web site projects over web app projects. I still use visual studio though because you get Nuget Packaging, you can install nuget packages to both types of projects.

在Visual Studio 2015中,我有点喜欢Web站点项目而不是Web应用程序项目。我仍然使用visual studio,因为你得到了Nuget Packaging,你可以在两种类型的项目中安装nuget包。

However a WebSite Project does not have a project file, you are literally just adding a folder to your solution.

但是,WebSite项目没有项目文件,您只需在解决方案中添加一个文件夹即可。

However you can still have code, but I prefer to put it in a separate project.

但是你仍然可以拥有代码,但我更喜欢把它放在一个单独的项目中。

In WebApp projects you have your Assets, Css, Views (razor, aspx etc), Controllers/Code Behinds etc all in one project and it just mashes together. I prefer to work with websites in two halves. The front end (css, js, images, "html/cshtml/aspx/ashx/.master/etc") and the back end (all the code).

在WebApp项目中,您可以在一个项目中拥有Assets,Css,Views(razor,aspx等),Controllers / Code Behinds等,它们只是在一起。我更喜欢与两半的网站合作。前端(css,js,images,“html / cshtml / aspx / ashx / .master / etc”)和后端(所有代码)。

So I create a Web Site project and a class Library to accompany it (in visual studio you can add references to the web site project). I add my class Library as a dependency and all Code is in the class Library. You can still have a global.asax, you just have to tell it that the code behind is in another dll (not the one that the site will compile to). MVC views, you just specify the namespaces like normal (the dll is referrence so the namespaces are there). And in WebForms you Just have to remember to include the assembly name with your type references that the code is in.

因此,我创建了一个Web站点项目和一个类库(在Visual Studio中,您可以添加对Web站点项目的引用)。我将我的类库添加为依赖项,所有代码都在类库中。你仍然可以有一个global.asax,你只需要告诉它后面的代码是在另一个dll(不是该网站将编译到的那个)。 MVC视图,你只需指定命名空间就像普通(dll是引用,所以命名空间就在那里)。在WebForms中,您只需记住将程序集名称包含在代码所在的类型引用中。

It's a little tedious to get use to, but when you do you have isolated structure, everything is in a place that makes sense and modularized in an easy to maintain way.

使用起来有点乏味,但是当你拥有孤立的结构时,一切都在一个有意义的地方,并以易于维护的方式模块化。

And the PLUS side is that because the Web Site is just a folder (no project file) it can be opened in Visual Studio Code easily, and other popular text editors making it easy for designers to work on the css/js/images etc (which are not in the code project). Keeping the layer designers separated, the designer sees just what they need to see.

而PLUS方面是因为网站只是一个文件夹(没有项目文件),它可以很容易地在Visual Studio Code中打开,而其他流行的文本编辑器使设计人员可以轻松地处理css / js / images等(这些不在代码项目中)。保持层设计师分离,设计师只看到他们需要看到的东西。

Now structure wise. I keep my code local on my machine checked into a subversion repository using Tortoise SVN and Visual SVN (java/.net shop). To test locally I install IIS and I set the website project up in IIS locally just like I would on the dev/prod servers.

现在结构明智。我使用Tortoise SVN和Visual SVN(java / .net shop)将我的代码保存在我的机器本地检查到subversion存储库。要在本地测试我安装IIS,我在本地IIS中设置网站项目,就像我在dev / prod服务器上一样。

Then I install MSDeploy on the dev/prod servers and I use the Publish web app feature via MSDeploy in visual studio and I use web.config transformations. So I have web.config transformations for dev and prod and the main web.config without transformations is for local testing (so it works for all devs on the project).

然后我在dev / prod服务器上安装MSDeploy,我在visual studio中通过MSDeploy使用Publish web app功能,我使用web.config转换。所以我有dev和prod的web.config转换,没有转换的主web.config用于本地测试(因此它适用于项目中的所有开发人员)。

To previous stated cons: Having a WebSite Project vs a WebApp Project doesn't mean multiple developers can't work on it, that's only if your WebSite Project is on some server some where and you are loading it directly from there which would be bad practice.

对于之前陈述的缺点:拥有WebSite项目与WebApp项目并不意味着多个开发人员无法对其进行操作,只有当您的WebSite项目位于某个服务器的某个位置并且您直接从那里加载它时才会这样做实践。

You can treat a WebSite Project just like any other Visual Studio project, local code, source control, multiple developers.

您可以像处理任何其他Visual Studio项目,本地代码,源代码控制和多个开发人员一样处理WebSite项目。

As a final note, an added benefit of separating your code is you can put all of your code in a shared project. Then you can create a Class Library for each port you might do, say one on straight .net 4.6 and another on .net core 5 and link in your shared project. As long as your code is compatible with both, it will build and you don't have any duplicated code files.

最后一点,分离代码的另一个好处是,您可以将所有代码放在共享项目中。然后,您可以为您可能执行的每个端口创建一个类库,例如直接.net 4.6上的一个,以及.net核心5上的另一个端口以及共享项目中的链接。只要您的代码与两者兼容,它就会构建,并且您没有任何重复的代码文件。

#1


3  

you'd better read this: http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx in my opinion it depends on what you are developing

你最好读这个:http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx在我看来这取决于你正在开发什么

#2


3  

Both function and perform similarly, but still differ in following ways:

功能和功能都相似,但在以下方面仍然有所不同:

Web application:

  • We can't include C# and VB pages in single web application.
  • 我们不能在单个Web应用程序中包含C#和VB页面。

  • We can set up dependencies between multiple projects.
  • 我们可以在多个项目之间建立依赖关系。

  • Can not edit individual files after deployment without recompiling.
  • 无需重新编译即可在部署后编辑单个文件。

  • Right choice for enterprise environments where multiple developers work unitedly for creating, testing and deployment.
  • 适用于多个开发人员统一工作以进行创建,测试和部署的企业环境。

Web site:

  • Can mix VB and C# page in single website.
  • 可以在单个网站中混合使用VB和C#页面。

  • Can not establish dependencies.
  • 无法建立依赖关系。

  • Edit individual files after deployment.
  • 部署后编辑单个文件。

  • Right choice when one developer will responsible for creating and managing entire website.
  • 当一个开发人员负责创建和管理整个网站时,正确的选择。

#3


2  

Web application projects works more like a traditional VS project, which has a project file, is compiled in one step and so on.

Web应用程序项目更像传统的VS项目,它有一个项目文件,一步编译等等。

Web site projects works more like classic ASP or PHP-sites. There is no project file (references are stored in the solution file), and pages are recompiled dynamically on the server. The nice thing with web sites is that you can just ftp to the server and change a file in a text editor. You dont need VS. Some may hate that, though.

网站项目更像是传统的ASP或PHP站点。没有项目文件(引用存储在解决方案文件中),页面在服务器上动态重新编译。网站的好处是你只需要ftp到服务器并在文本编辑器中更改文件。你不需要VS.但有些人可能会讨厌这一点。

It probably depends on your background. If you are used to ASP or PHP style development, web site projects will seem more natural to you. If you have a traditional application developer background, web application projects will seem more natural.

这可能取决于你的背景。如果您习惯于ASP或PHP风格开发,那么网站项目对您来说似乎更自然。如果您拥有传统的应用程序开发人员背景,那么Web应用程序项目将更加自然。

#4


2  

If you're using Team Foundation Server for source control, you'll probably have to use a Web Application Project, as you need a .csproj file.

如果您使用Team Foundation Server进行源代码管理,则可能必须使用Web应用程序项目,因为您需要.csproj文件。

There are more details from Jeff Atwood himself: Web Site Projects vs. Web Application Projects

Jeff Atwood本人提供了更多详细信息:网站项目与Web应用程序项目

Web Site web projects are particularly painful in Team System due to the lack of a physical file that contains project information and metadata. For example, it's impossible to check in code analysis rules on Web Site projects, because the code analysis rules are stored entirely on the client!

由于缺少包含项目信息和元数据的物理文件,因此Web System Web项目在Team System中尤其痛苦。例如,无法检查Web站点项目上的代码分析规则,因为代码分析规则完全存储在客户端上!

#5


1  

I prefer a website. A website is a collection of files in a directory. It becomes more portable and deployable. A web application clouds the issue with a project file.

我更喜欢网站。网站是目录中文件的集合。它变得更加便携和可部署。 Web应用程序通过项目文件来解决问题。

#6


0  

Personally I use web application projects exclusively now. I actually converted a rather web site to a web application because of compilation times for the web site.

我个人现在专门使用Web应用程序项目。由于网站的编译时间,我实际上将一个相当网站转换为Web应用程序。

I also use pre-build events to move configuration specific configuration files around and pre-build and post-build events are not available in web sites.

我还使用预构建事件来移动配置特定的配置文件,并且在网站中不提供预构建和后构建事件。

#7


0  

In Visual Studio 2015, I've come to somewhat prefer web site projects over web app projects. I still use visual studio though because you get Nuget Packaging, you can install nuget packages to both types of projects.

在Visual Studio 2015中,我有点喜欢Web站点项目而不是Web应用程序项目。我仍然使用visual studio,因为你得到了Nuget Packaging,你可以在两种类型的项目中安装nuget包。

However a WebSite Project does not have a project file, you are literally just adding a folder to your solution.

但是,WebSite项目没有项目文件,您只需在解决方案中添加一个文件夹即可。

However you can still have code, but I prefer to put it in a separate project.

但是你仍然可以拥有代码,但我更喜欢把它放在一个单独的项目中。

In WebApp projects you have your Assets, Css, Views (razor, aspx etc), Controllers/Code Behinds etc all in one project and it just mashes together. I prefer to work with websites in two halves. The front end (css, js, images, "html/cshtml/aspx/ashx/.master/etc") and the back end (all the code).

在WebApp项目中,您可以在一个项目中拥有Assets,Css,Views(razor,aspx等),Controllers / Code Behinds等,它们只是在一起。我更喜欢与两半的网站合作。前端(css,js,images,“html / cshtml / aspx / ashx / .master / etc”)和后端(所有代码)。

So I create a Web Site project and a class Library to accompany it (in visual studio you can add references to the web site project). I add my class Library as a dependency and all Code is in the class Library. You can still have a global.asax, you just have to tell it that the code behind is in another dll (not the one that the site will compile to). MVC views, you just specify the namespaces like normal (the dll is referrence so the namespaces are there). And in WebForms you Just have to remember to include the assembly name with your type references that the code is in.

因此,我创建了一个Web站点项目和一个类库(在Visual Studio中,您可以添加对Web站点项目的引用)。我将我的类库添加为依赖项,所有代码都在类库中。你仍然可以有一个global.asax,你只需要告诉它后面的代码是在另一个dll(不是该网站将编译到的那个)。 MVC视图,你只需指定命名空间就像普通(dll是引用,所以命名空间就在那里)。在WebForms中,您只需记住将程序集名称包含在代码所在的类型引用中。

It's a little tedious to get use to, but when you do you have isolated structure, everything is in a place that makes sense and modularized in an easy to maintain way.

使用起来有点乏味,但是当你拥有孤立的结构时,一切都在一个有意义的地方,并以易于维护的方式模块化。

And the PLUS side is that because the Web Site is just a folder (no project file) it can be opened in Visual Studio Code easily, and other popular text editors making it easy for designers to work on the css/js/images etc (which are not in the code project). Keeping the layer designers separated, the designer sees just what they need to see.

而PLUS方面是因为网站只是一个文件夹(没有项目文件),它可以很容易地在Visual Studio Code中打开,而其他流行的文本编辑器使设计人员可以轻松地处理css / js / images等(这些不在代码项目中)。保持层设计师分离,设计师只看到他们需要看到的东西。

Now structure wise. I keep my code local on my machine checked into a subversion repository using Tortoise SVN and Visual SVN (java/.net shop). To test locally I install IIS and I set the website project up in IIS locally just like I would on the dev/prod servers.

现在结构明智。我使用Tortoise SVN和Visual SVN(java / .net shop)将我的代码保存在我的机器本地检查到subversion存储库。要在本地测试我安装IIS,我在本地IIS中设置网站项目,就像我在dev / prod服务器上一样。

Then I install MSDeploy on the dev/prod servers and I use the Publish web app feature via MSDeploy in visual studio and I use web.config transformations. So I have web.config transformations for dev and prod and the main web.config without transformations is for local testing (so it works for all devs on the project).

然后我在dev / prod服务器上安装MSDeploy,我在visual studio中通过MSDeploy使用Publish web app功能,我使用web.config转换。所以我有dev和prod的web.config转换,没有转换的主web.config用于本地测试(因此它适用于项目中的所有开发人员)。

To previous stated cons: Having a WebSite Project vs a WebApp Project doesn't mean multiple developers can't work on it, that's only if your WebSite Project is on some server some where and you are loading it directly from there which would be bad practice.

对于之前陈述的缺点:拥有WebSite项目与WebApp项目并不意味着多个开发人员无法对其进行操作,只有当您的WebSite项目位于某个服务器的某个位置并且您直接从那里加载它时才会这样做实践。

You can treat a WebSite Project just like any other Visual Studio project, local code, source control, multiple developers.

您可以像处理任何其他Visual Studio项目,本地代码,源代码控制和多个开发人员一样处理WebSite项目。

As a final note, an added benefit of separating your code is you can put all of your code in a shared project. Then you can create a Class Library for each port you might do, say one on straight .net 4.6 and another on .net core 5 and link in your shared project. As long as your code is compatible with both, it will build and you don't have any duplicated code files.

最后一点,分离代码的另一个好处是,您可以将所有代码放在共享项目中。然后,您可以为您可能执行的每个端口创建一个类库,例如直接.net 4.6上的一个,以及.net核心5上的另一个端口以及共享项目中的链接。只要您的代码与两者兼容,它就会构建,并且您没有任何重复的代码文件。