ELMAH在主题页面中的错误

5

我有一个主题页面,其中主题是在HTTP模块内选择的。

public void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
    Page p = HttpContext.Current.Handler as Page;

    if (p != null)
    {
        //get theme
        string theme = GetTheme(HttpContext.Current.Request.Url.Host);

        Debug.WriteLine(String.Format("Loading theme {0}", theme));

        //set theme of page
        p.Theme = theme;
    }
}

现在当我请求 elmah.axd 时,会抛出以下异常:

使用主题样式表需要在页面上添加一个头控件(例如:<head runat="server"></head>)。

当我禁用 http 主题模块时,一切都正常,elmah.axd 页面显示出来。我认为这是 ErrorLogPage 中的小 bug。ErrorLogPage 应该能够处理页面可能提供的主题,或者干脆忽略给定的主题。

目前我使用以下解决方法:

private const string ELMAH_ERROR_PAGE = "Elmah.ErrorLogPage";

        if (p.GetType().FullName != ELMAH_ERROR_PAGE)
        {
            p.Theme = theme;
        }

你有更好的想法或想法吗?

Gr

Martijn

荷兰


页面或母版页的head部分是否有runat="server" - Russ Bradberry
1个回答

0
您的问题已经有解决方案:
如何从使用HTTPModule的页面中排除某些页面

You could use an HTTPHandler instead of an HTTPModule. Handlers let you specify a path when you declare them in Web.Config.

<add verb="*" path="/validate/*.aspx" type="Handler,Assembly"/>

If you must use an HTTPModule, you could just check the path of the request and if it's one to be excluded, bypass the validation.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接