ASP.NET Website vs ASP.NET Web Application project

ASP.NET Website vs ASP.NET Web Application project

Web Application Projects in Microsoft Visual Studio

Microsoft Visual Studio provides two options for creating web applications: one is the ASP.NET website project and the other is ASP.NET Web application project. Way back in 2013 or maybe even long before that, Microsoft has been recommending use of ASP.NET Web application project for web applications. The use of ASP.NET Website template has been discouraged because it has a lot of issues which we will discuss below.

ASP.NET website project

  • There is no project file (.csproj or .vbproj). All the files in a folder structure are automatically included in the site.
  • The source code is typically compiled dynamically (automatically) by ASP.NET on the server the first time a request is received after the site has been installed or updated.
  • One can precompile the site on a dev computer. However, by default, compilation produces multiple assemblies. Whenever an .aspx page is modified, it produces a new assembly for that page with a certain unique id appended to the .aspx page name before the .dll extension. This means if a certain .aspx page is edited 20 times, it would by default produce 20 assemblies for that page alone. The more weird fact is that only one of these 20 assemblies (latest one) is used. This is weird, insecure, cumbersome and too risky. What is some administrator deletes one of the page assemblies and that's the one which is latest? That page won't work on your web application and it won't be easy for your dev team to detect and fix the defect. What if this happens in production? Think about it before even thinking of using ASP.NET Website project again.

ASP.NET web application project

  • In this type of project/template, a Visual Studio project file (.csproj or .vbproj) is created that stores information about the project, such as the list of files that are included in the project, and any internal or external references.
  • Visual Studio allows building the source code on the computer that is used for development and by default, compilation of code files including the code-behind files (excluding .aspx and .ascx files) produces a single assembly which is easy to handle and has typically the name of the web application before the extension (.dll).
  • Even if your .aspx pages are modified innumerable times, the single assembly itself is rebuilt. Theer are no multiple .dlls and confusing names of the assemblies like the ASP.NET website project.

How to find out if you have an ASP.NET Website or an ASP.NET Web application project?

Go to your IIS Server manager console, and locate the web application you are interested in. Right click it in the connections tree and click on Explore button. This will take you to the folder where the web application binaries are saved. If the folder has a directory called "bin" and it has a lot of files that have similar names except for a weird-looking IDs appended to them (e.g. MyPageOne_abcdefghi.dll; MyPageOne_jklmnopqr.dll and so on), you have an ASP.NET website rather than ASP.NET Web application.

Although one can compile their entire site into a single .dll for their ASP.NET Website, people do not seem to do that somehow and what is created is a complete mess.

The main trouble with an ASP.NET website is that due to the default large number of .dll files for each page and with so many of such pages, it becomes prone to security risks, slow load time and next-to-impossible debugging.

On the other hand, an ASP.NET web application is more secure, loads faster (with the same code and number of .aspx pages as used in the similar ASP.NET website) and are easy to debug.

Choice is yours.

References

Web Application Projects versus Web Site Projects in Visual Studio | Microsoft Docs This article itself is very old (2013) and Microsoft is not updating that page regularly. However, the information in that page still holds true.




Kelly Murphy

Principal Consultant at Code Guru Too, Inc.

1 年

Great article. Thank you!

回复
Shiva Nandyala

Software Engineer | .NET | Clean Code

1 年

Very informative article. Thanks!

回复
Prasad N.

Technology Disclaimer: My views expressed here on LinkedIn are my own and they do not represent anyone else.

3 年

There are many who have developed ASP.NET Websites in the name of Web applications. Using an ASP.NET website template for adding a little dynamism (using C#/VB.NET code) in "App_Code" folder helps quickly build up some interactivity in a website. However, doing this in a huge/enterprise web applications is entirely wrong and is an anti-pattern. Such web applications developed with ASP.NET website template tend to be messy, unmanageable, buggy, difficult to debug and extremely low-performance. Developers who have supported such an anti-pattern have not understood what a web application is and what web application performance is.

回复

要查看或添加评论,请登录

Prasad N.的更多文章

社区洞察

其他会员也浏览了