这是我的代码,我想在每次加载/刷新应用程序时自动调用我的自定义方法(Application_My()
),如Application_OnEndRequest()
。
提前致谢。
<%@ Application Language="C#" %>
<script runat="server">
// THis code will be executed automatically when page is reloaded everytime
/*protected void Application_OnEndRequest()
{
Response.Write("Thsi page is executed on=" + DateTime.Now.ToString());
}*/
// how to call below method automatically when page is reloaded everytime
//such as above
protected void Application_My()
{
Response.Write("Hi welcome");
}
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
答案 0 :(得分:1)
protected void Application_EndRequest(object sender, EventArgs e)
{
Application_My();
}
但是,请注意,这是由您的aspnet管道管理的所有内容调用的,因此您可能会调用css和图像请求。
你可以添加Debug.WriteLine(Request.Url);到上面的代码,看看当你进入你的网站时会发生什么。