Asp.net

保護 ELMAH,同時還可以通過 RSS 閱讀器訪問它

  • May 21, 2012

我們在應用程序中使用 ELMAH 錯誤異常日誌記錄。我想保護 ELMAH 不受普通使用者的影響,同時仍然讓應用程序的管理員/開發人員可以使用它。

當您在 web.config 中使用表單身份驗證設置安全性時,您將失去訪問 RSS 提要的能力。我希望能夠保護 ELMAH,但仍然通過對 axd 的身份驗證,以便能夠從 RSS 閱讀器訪問 RSS 提要(即 /elmah.axd/rss)。

認為 http 身份驗證是正確的,因為我可能可以使用以下 url 語法http://username:password@somedomain.com/elmah.axd/rss訪問 rss 提要,我假設您需要設置身份驗證模式 = windows”在 web.config 中的特定路徑上。一個問題是如何在虛擬文件上設置憑據?

查看 Google 會帶回CodeProject上關於如何使用 cookie 設置身份驗證傳遞的這篇文章。這是解決我問題的好方法嗎?

有沒有其他更好的方法可以在安全的同時訪問 RSS 提要?

謝謝。

在單個 ASP.NET 網站中支持 HTTP 身份驗證和表單身份驗證

基本上,您將一個名為 MADAM 的 dll 添加到您的項目中,調整您的 web.config 並配置您希望將哪些文件作為 Basic 而不是 Forms 進行身份驗證:

<configuration>
   <configSections>
       <sectionGroup name="madam">
           <section name="userSecurityAuthority" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
           <section name="formsAuthenticationDisposition" type="Madam.FormsAuthenticationDispositionSectionHandler, Madam" />
       </sectionGroup>
   </configSections>

   ...

   <madam>
       <userSecurityAuthority ... />

       <formsAuthenticationDisposition>
           <discriminators all="[true|false]">
               ...
           </discriminators>
       </formsAuthenticationDisposition>
   </madam>

   ...

   <system.web>
       <httpModules>
           &lt;add name="FormsAuthenticationDisposition" type="Madam.FormsAuthenticationDispositionModule, Madam" /&gt;
           &lt;add name="AuthenticationModule" type="MADAM Authentication Module Type" /&gt;
   &lt;/system.web&gt;
&lt;/configuration&gt;

這很容易設置並解決了我能夠驗證 elmah.axd 並且仍然能夠使用基本身份驗證憑據訂閱 RSS 提要的問題。

旁注 MADAM 是由寫 ELMAH 的同一個人寫的,巧合嗎?

引用自:https://stackoverflow.com/questions/1046234