I was following some tutorials and created a new C# .Net Framework 4.6 Application as a web form type. When working on the project I noticed it doesn't have a Main Function to add logic too, it also doesn't have a program.cs, yet it is able to build fine. Why is that, I was under the impression that all C# programs need a main function to start as there entry point, and have seen multiple resources on the web stating that(https://www.c-sharpcorner.com/blogs/main-method-in-c-sharp, https://www.completecsharptutorial.com/basic/main-method.php).
If we don't need it what is replacing it, and serving as the code entry point. I also noticed that there is no program.cs what is the reason for this. I have been researching but I find the answers posted very contradictory to what is actually in the code.
CodePudding user response:
Because in the old (.NET Framework) it runs in process - the startup code is for some reason that are MOSTLY historical (ASP pre .NET) in a file GLOBAL.ASAX
What is the purpose of global.asax in asp.net
Again, this really goes back to asp.net mvc following up on the concepts of asp (pre .net). It is rectified in the Core versions where basically a program starts for the application.
CodePudding user response:
ASP.NET applications do have an entry point but in a roundabout way.
For a .NETFramework ASP.NET Web Forms app, you are usually going to have a Global.aspx.cs
file with an Application_Start
method that does your application configuration (routes etc).
CodePudding user response:
A web form or app is not a "program". It is a collection of pages and other classes that are referenced by the underlying ASP.NET service.
There are many more details to the ASP.NET ecosystem, but the main reason is because a site is not a "program" that needs an entry point. Only console apps and windows apps need an entry point.
CodePudding user response:
Because in a C# Program the main() is the entry point of your program. Without it the program can't start
for more information look here: https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/main-command-line