2017-07-28 12 views
0

私はElmahをNuget経由でMVCプロジェクトに追加しました。安全なElmahリモートアクセスが動作しない

私は、リモートアクセスをelmahログに設定することに関してallowremoteaccessを読んでいます。

現時点では、認証されずにログを表示できます。それがなぜなのか分かりません。

「Foo」と言ってみましょう。

ここでは、Elmahに関してWeb.configの外観を抜粋しています。

<appSettings> 
    <add key="elmah.mvc.requiresAuthentication" value="true" /> 
    <add key="elmah.mvc.allowedRoles" value="Admin" /> 
    <add key="elmah.mvc.allowedUsers" value="Foo" /> 
</appSettings> 

<modules> 
    <remove name="FormsAuthentication" /> 
    <remove name="ApplicationInsightsWebTracking" /> 
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /> 
    <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /> 
    <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /> 
</modules> 

    <authorization> 
    <allow roles="admin" /> 
    <allow users="foo"/> 
    </authorization> 

編集、フルweb.configファイル:あなたはELMAHとElmah.MVCから設定のスタイルを組み合わせているよう

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    https://go.microsoft.com/fwlink/?LinkId=301880 
    --> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <sectionGroup name="elmah"> 
     <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" /> 
     <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" /> 
     <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" /> 
     <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" /> 
    </sectionGroup> 
    </configSections> 
    <connectionStrings> 
connection string here... 
    </connectionStrings> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    <add key="elmah.mvc.requiresAuthentication" value="true" /> 
    <add key="elmah.mvc.allowedRoles" value="Admin" /> 
    <add key="elmah.mvc.allowedUsers" value="habib" /> 
    </appSettings> 
    <system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2" /> 
    <httpModules> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /> 
     <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /> 
     <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> 
     <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /> 
    </httpModules> 
    </system.web> 
    <system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" /> 
     <remove name="ApplicationInsightsWebTracking" /> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /> 
     <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /> 
     <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /> 
     <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /> 
    </modules> 
    <validation validateIntegratedModeConfiguration="false" /> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /> 
     <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" /> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
    </compilers> 
    </system.codedom> 
    <elmah> 
    <!-- 
     See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
     more information on remote access and securing ELMAH. 
    --> 
    <security allowRemoteAccess="0" /> 
    </elmah> 
    <location path="elmah.axd" inheritInChildApplications="false"> 
    <system.web> 
     <httpHandlers> 
     <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> 
     </httpHandlers> 
     <!-- 
     See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
     more information on using ASP.NET authorization securing ELMAH. 

     <authorization> 
     <allow roles="admin" /> 
     <deny users="*" /> 
     </authorization> 
     --> 
     <authorization> 
     <allow roles="admin" /> 
     <deny users="*" /> 
     <!--<allow users="habib"/>--> 
     </authorization> 
     <globalization culture="en-GB"/> 

    </system.web> 
    <system.webServer> 
     <handlers> 
     <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" /> 
     </handlers> 
    </system.webServer> 
    </location> 
    <system.webServer> 
    <!--<rewrite> 
     <rules> 
     <rule name="Enforce canonical hostname" stopProcessing="true"> 
      <match url="(.*)" /> 
      <conditions> 
      <add input="{HTTP_HOST}" negate="true" pattern="^www\.my-worksmart\.com$" /> 
      </conditions> 
      <action type="Redirect" url="https://www.my-worksmart.com/{R:0}" redirectType="Permanent" /> 
     </rule> 
     </rules> 
    </rewrite>--> 
    </system.webServer> 
</configuration> 

答えて

0

あなたの例では<autorization>要素を見て、それが見えます。 Elmah.MVCを使用する場合は、appSettingsでのみ認可を指定し、<location>要素(認可を含む)は含めないでください。

私はちょうど新しいプロジェクトで、次のappSettingsをテストした(あなたがしたい場合、私はあなたと共有することができますか?):追加の助けを必要と

<add key="elmah.mvc.disableHandler" value="false" /> 
<add key="elmah.mvc.disableHandleErrorFilter" value="false" /> 
<add key="elmah.mvc.requiresAuthentication" value="true" /> 
<add key="elmah.mvc.IgnoreDefaultRoute" value="false" /> 
<add key="elmah.mvc.allowedRoles" value="*" /> 
<add key="elmah.mvc.allowedUsers" value="Thomas" /> 
<add key="elmah.mvc.route" value="elmah" /> 
<add key="elmah.mvc.UserAuthCaseSensitive" value="true" /> 

場合は、おそらく全体のweb.configファイルを共有し、バグがどこにあるかをより明確にする。

+0

あなたの回答に感謝します。私は最初にELMAHで始まり、ナゲットパッケージを見つけることになりました。これに基づいて、私はappSettingsの外で認可を削除する必要がありますか?私は私のweb.configを投稿します、はい、間違いなくあなたが試したことを共有してください。私のOPを更新します – Haris

+0

@Haris少なくとも ""要素は必要ありません。Elmah.MVCはELMAHのルートを追加するためです。私のコードから残りのアプリケーション設定を追加して、何か変わったかどうか確認できますか? – ThomasArdal

+0

ロケーション・エレメントを削除しましたが、ログにアクセスする方法がわからない、domain/elmah.axdにアクセスしようとしたときに受け取ったエラーは404でした。編集 - 私はちょうどelmah.ioのブログを読んで、それは私のためにその質問に答える。 https://docs.elmah.io/logging-to-elmah-io-from-aspnet-mvc/ワークステーションに戻ったらもう一度試してみましょう:)そしてあなたに戻ってください。 – Haris

関連する問題