ASP.NET入口点? [英] ASP.NET Entry Point?

查看:92
本文介绍了ASP.NET入口点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅创建了一个空白的"ASP.NET Web应用程序".入口点在哪里?

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

我看到"Default.aspx",它似乎是调用的默认模板.我猜"Site.Master"充当布局文件."Global.asax"似乎为事件处理提供了一些方法存根.然后"Web.config"似乎具有一些特定于站点的设置,例如数据库连接字符串和一些身份验证内容.

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.

但是,在任何地方都看不到任何路由"或任何表明默认情况下应调用"Default.aspx"或应使用"Global.asax"来处理事件的内容.这些东西在哪里指定?它融入了ASP的核心吗?我不能通过一种C#方法过滤所有请求,然后委托我如何吗?并返回某种Http响应?

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.

HttpApplication 类包含应用程序的第一行代码.它的构造函数非常适合您的应用程序.从文档中:

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:

在初始化所有核心应用程序对象之后,通过创建HttpApplication类的实例来启动应用程序.

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

有两种规范的方法可以编写针对新请求而命中的第一行代码.两者都涉及创建Global.asax文件并处理其事件.

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.

要处理应用程序事件或方法,可以在应用程序的根目录中创建一个名为Global.asax的文件.

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

您将要处理 Application_Start 和/或 Application_BeginRequest .

  • Application_Start 适用于在对应用程序的第一个请求时被命中的代码.每次我们重新启动应用程序时,下一个请求将在此处输入.这是每次应用程序启动.
  • 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.

当然,这一切都随ASP.NET Core改变.

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

这篇关于ASP.NET入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆