【问题标题】:Creating a log file detect on click of a button单击按钮创建日志文件检测
【发布时间】:2012-09-03 03:50:13
【问题描述】:

有什么方法可以让我追踪按钮点击了哪个网页。

例如 默认1.aspx 按钮1点击

然后在我的日志文件中。我的日志文件将记录该按钮 1 在默认页面中单击。

是否可以在 global.asax 文件的 beginrequest 事件中执行此操作? 请教我一个解决方案。

这是我的 global.asax 代码

 protected void Application_Start(object sender, EventArgs e)
    {

        // Set logfile name and application name variables

        string l4net = Server.MapPath("~/log4Net.config");
        log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(l4net));


    }

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        //What should i code here???

    }

非常感谢任何帮助

【问题讨论】:

    标签: c# asp.net log4net trace


    【解决方案1】:

    是的,你当然可以做到。

    您可以使用

    获取当前页面
    var page = HttpContext.Current.Request.Url;
    

    并且按钮存在于事件目标中

    var button = HttpContext.Current.Request.Params["__EVENTTARGET"];
    

    这将为您获取控件的 ClientID,但您应该能够从中提取控件 ID。

    【讨论】:

    • 谢谢你。顺便说一句,你的意思是提取控件 ID?
    • 我试试 adi 。我只能获取当前页面。我无法获得点击了哪个按钮:(
    • ClientID 是 asp.net 为嵌套在容器中的控件生成的字段。通常,如果您的按钮名为 Btn1,例如在 Panel1 中,CliendID 可能看起来像 ct100_Panel1_Btn1
    • 调试和检查HttpContext.Current.Request.Params 集合。如果你点击了一个按钮,__EVENTTARGET 应该会出现。
    • __EVENTTARGET 只返回空值 :(
    猜你喜欢
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    相关资源
    最近更新 更多