开发者

ASP.NET Entry Point?

Just created a blank "ASP.NET Web Application". Where's the entry point?

I see "Default.aspx" which seems to be the default template that calls. "Site.Master" which I guess acts as a layout file. "Global.asax" that seems to provide some method stubs for event handling. And then "Web.config" which seems to have some site-specific settings such as a DB connection string, and some authentication stuff.

But no where do I see any "routes" or anything to indicate that "Default.aspx" should be called by default, or "Global.asax" should be used to handle events. Where's this stuff specified? Is it baked into the core of ASP? Can't I filter all the requests through one C# method and then 开发者_开发知识库delegate how I please? And return some sort of Http response?


I think I wanted to know the first line of code that gets hit when a new request comes in.

The HttpApplication class contains the first line of code of your application. Its constructor is very much the entry point for your application. From the docs:

After all core application objects have been initialized, the application is started by creating an instance of the HttpApplication class.

There are two canonical ways to write the first line of code that gets hit for a new request. Both involve creating a Global.asax file and handling its events.

To handle application events or methods, you can create a file named Global.asax in the root directory of your application.

You will want to handle Application_Start and/or Application_BeginRequest.

  • Application_Start is for code that gets hit on the very first request to the application. Each time we restart the application, the next request will enter here. This is per application startup.
  • Application_BeginRequest is for code that gets hit on each request to the application. This is per request.

Of course, this all changes with ASP.NET Core.


There's no notion of entry point. The way it works is that the user sends an HTTP request to an url and this url sends a response to the user. In the properties of the project you could configure which URL to launch in Visual Studio when you hit F5 because by default it launches the file you are currently editing.

Also the web server has a notion of default document i.e. if you don't specify any page it will load the default documents in the order they are configured:

ASP.NET Entry Point?


the entry is an IIS ISAPI extension that processes Asp.net requests. If you want the routing you could use Asp.net mvc, or use an HttpModule to intercept and route the requests.

see more about Asp.net here. https://web.archive.org/web/20100620062357/https://www.west-wind.com/presentations/howaspnetworks/howaspnetworks.asp


By default, ASP.NET just uses the physical file paths for determining which page to display. Default.aspx is the default either because it is the startup file of your project, or because it is mapped as the default document of your root folder in IIS.

You can optionally use the routing components added to the framework as part of ASP.NET MVC if you want custom routing. There's a guide on how to use this here


The file called by default is specified on the IIS, generally is default.aspx.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜