3

我有一个非常基本的 asp.net 应用程序,它依赖于母版页的 INIT 事件来通过会话对象验证用户。是的,我知道这是次优的。

我想向其中添加 ELMAH,但在不使用表单身份验证和 web.config 允许/拒绝设置的情况下找不到任何保护控制台的参考。

是否有另一种方法来保护不依赖于表单身份验证的 elmah.axd 文件?

4

3 回答 3

3

本文介绍如何将 Elmah 错误处理程序包装在另一个允许访问会话状态的事件处理程序中:

http://groups.google.com/group/elmah/msg/a0aa776d348ba97e

在 Global.asax 中,您可以拥有如下内容:

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
    // Get the filename being requested
    string filename = Path.GetFileName(Request.Path).ToLower();

    // Verify that a user is logged in by checking the session
    bool isValid = (HttpContext.Current.Session["User"] != null);

    // Throw error if invalid
    if (filename == "elmah.axd" && !isValid)
        throw new SecurityException("Access to elmah.axd is denied");
}

标准 Elmah 处理程序没有实现 IRequiresSessionState 或 IReadOnlySessionState,因此您必须创建另一个事件处理程序来包装它,如上面提到的链接中所述。否则,您将无法访问 Application_PreRequestHandlerExecute 事件中的会话。

于 2010-03-19T18:23:47.507 回答
1

我是 ELMAH 的 MySQL 支持开发人员之一。允许/拒绝选项不是特定于 Web 表单的。他们可以与任何提供商合作。

  1. 要实现自定义的,您需要使用IPrincipal接口。
  2. 来自允许/拒绝角色的角色是从IPrincipal的这个IsInRole方法中提取的。
  3. 在 global.asax 或您自己的 IHttpHandler 中的 Request_Authentication 上,您需要创建 IPrincipal 对象并将其设置为 Context.User 对象。像这样的东西:

    private void Request_Authenticate (object sender, EventArgs e) {
        // do checks and create IPrincipal object
        IPrincipal user = new MyPrincipal(...);
        Context.User = user;
    }
    
  4. 然后,当为您的 elmah.axd 处理程序检查角色时,它将针对此自定义对象而不是 Web 表单。

于 2010-03-19T18:33:10.633 回答
0

开箱即用,远程访问被禁用,因此您只能从本地计算机访问错误日志。这里还有更多: http ://code.google.com/p/elmah/wiki/SecuringErrorLogPages

于 2009-05-06T08:16:33.653 回答