gpt4 book ai didi

ASP.NET 入口点?

转载 作者:行者123 更新时间:2023-12-02 03:55:56 25 4
gpt4 key购买 nike

刚刚创建了一个空白的“ASP.NET Web 应用程序”。入口点在哪里?

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

但是我在哪里看到任何“路由”或任何指示默认情况下应调用“Default.aspx”或应使用“Global.asax”来处理事件的内容。这个东西具体在哪里?它是否已融入 ASP 的核心?我不能通过一种 C# 方法过滤所有请求,然后按照我的意愿委托(delegate)吗?并返回某种 Http 响应?

最佳答案

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

HttpApplication 类包含应用程序的第一行代码。它的构造函数很大程度上是您的应用程序的入口点。 From the docs :

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

有两种规范的方法可以编写新请求命中的第一行代码。两者都涉及创建 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 用于在对应用程序的每个请求上命中的代码。这是根据请求。

当然,这一切都随着 ASP.NET Core 的改变而改变。

关于ASP.NET 入口点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4264623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com