2

这是我的代码,我想在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)
    {

    }

4

1 回答 1

1
protected void Application_EndRequest(object sender, EventArgs e)
{
    Application_My();
}

但是,请注意,这会为您的 aspnet 管道管理的所有内容调用,因此您可能会在 css 和图像请求上被调用。

您可以添加 Debug.WriteLine(Request.Url); 查看上面的代码,看看当您进入您的网站时会发生什么。

于 2013-05-19T18:11:50.233 回答