【问题标题】:How to configure ELMAH to show log just for Sitecore user如何将 ELMAH 配置为仅为 Sitecore 用户显示日志
【发布时间】:2013-01-10 14:50:40
【问题描述】:

我在我的 Sitecore 解决方案中添加了 Elmah 工具,实际上我是在这里做的 http://newguid.net/sitecore/2011/using-elmah-for-error-logging-within-sitecore/ 我启用的只有一个卷是 allowRemoteAccess 属性,

<elmah>
<security allowRemoteAccess="1" />  
</elmah>

现在任何地方的每个人都可以使用日志,但我只想为登录(授权)到 sitecore 的用户(sitecore 用户)显示它

我该如何管理它?

谢谢。

【问题讨论】:

    标签: asp.net sitecore sitecore6 elmah


    【解决方案1】:

    不确定Elmah 现在内置了什么,但我曾经这样做过:

    <location path="elmah.axd">
        <system.web>
            <authorization>
                <allow roles="SITECORE_USERS"/> <!---put your role here-->
                <deny users="*"/> 
            </authorization>
        </system.web>
    </location>
    

    Securing Elmah RSS Feeds in ASP.NET website

    【讨论】:

    • 您好,谢谢,但它在我这边不起作用。你能告诉我,也许我需要为 sitecore 设置一些其他设置吗?
    • 请注意站点核心使用的用户角色,我只是做了一个例子。
    • 我明白了,但我尝试使用 aspnet_Roles 表中的角色,但不起作用。
    • 我发现了其他更有趣和灵活的解决方案自定义 IHttpModule + IRequestAuthorizationHandler
    【解决方案2】:

    我在研究了elmah源代码和这篇文章http://dotnetslackers.com/articles/aspnet/Securing-ELMAH-with-Independent-HTTP-Authentication.aspx后找到了解决方案。用户可以为自定义 IHttpModule 实现 IRequestAuthorizationHandler 接下来我做了:

     public class SitecoreAuthModule :IHttpModule, IRequestAuthorizationHandler
    {
        public bool Authorize(HttpContext context)
        {
            return SC.Context.User.IsAdministrator;
        }
    
        public void Init(HttpApplication context)
        {
            context.AuthenticateRequest += new EventHandler(ContextAuthenticateRequest); ;
        }
    
        void ContextAuthenticateRequest(object sender, EventArgs e)
        {
            var context = sender as HttpApplication;
            if (context.Request.Path.IndexOf("elmah.axd",
                StringComparison.InvariantCultureIgnoreCase) < 0)
                return;
        }
    
        public void Dispose()
        {
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-01
      • 2016-02-02
      • 2013-03-12
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多