5

/elmah.axdへのリクエストをUmbraco管理者ユーザーに制限するにはどうすればよいですか。

UmbracoメンバーシップとロールプロバイダーはUmbracoメンバーには適用されますが、ユーザーには適用されないことを理解しています-Umbracoユーザーアカウントには、このようなweb.configで使用できるユーザー名またはロール(「管理者」など)がないようです。 :

<location path="elmah.axd">
  <system.web>
    <authorization>
        <allow roles="Admins" />
        <deny users="*" />
    </authorization>
  </system.web>
</location>

これは、他のASP.NetアプリケーションでELMAHを保護するための推奨される方法です。

Umbracoでこれを行った人はいますか?

4

2 に答える 2

6

elmah.axdへのリクエストをインターセプトするHTTPモジュールを作成し、Umbraco管理者のみに表示を許可することで問題を解決しました。モジュールコードは次のとおりです。

namespace MyNamespace
{
    using System;
    using System.Configuration;
    using System.Web;
    using System.Web.Configuration;

    using umbraco.BusinessLogic;

    public class ElmahSecurityModule : IHttpModule
    {
        private HttpApplication _context;

        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            this._context = context;
            this._context.BeginRequest += this.BeginRequest;
        }

        private void BeginRequest(object sender, EventArgs e)
        {
            var handlerPath = string.Empty;

            var systemWebServerSection = (HttpHandlersSection)ConfigurationManager.GetSection("system.web/httpHandlers");

            foreach (HttpHandlerAction handler in systemWebServerSection.Handlers)
            {
                if (handler.Type.Trim() == "Elmah.ErrorLogPageFactory, Elmah")
                {
                    handlerPath = handler.Path.ToLower();
                    break;
                }
            }

            if (string.IsNullOrWhiteSpace(handlerPath) || !this._context.Request.Path.ToLower().Contains(handlerPath))
            {
                return;
            }

            var user = User.GetCurrent();

            if (user != null)
            {
                if (user.UserType.Name == "Administrators")
                {
                    return;
                }
            }

            var customErrorsSection = (CustomErrorsSection)ConfigurationManager.GetSection("system.web/customErrors");

            var defaultRedirect = customErrorsSection.DefaultRedirect ?? "/";

            this._context.Context.RewritePath(defaultRedirect);
        }
    }
}

...およびweb.config:

<configuration>
    <system.web>
        <httpModules>
            <add name="ElmahSecurityModule" type="MyNamespace.ElmahSecurityModule" />
        </httpModules>
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="ElmahSecurityModule" type="MyNamespace.ElmahSecurityModule" />
        </modules>
    </system.webServer>
</configuration>
于 2012-08-30T16:34:16.640 に答える
0

ELMAHをUmbracoと正しく統合するには、ELMAHを変更する必要があると思います

この記事はあなたが探しているものかもしれません

于 2012-05-04T08:15:15.087 に答える