使用通用asp.net处理程序(* .ashx)的匿名身份验证

时间:2017-11-03 16:22:58

标签: asp.net windows-authentication generic-handler

我有一个启用了Windows身份验证的asp.net webforms应用程序。我需要在包含图像的网站中的“测试”文件夹上启用匿名身份验证。我通过添加

来做到这一点
<location path="Test">
<system.webServer>           
  <security>
    <authentication>          
      <anonymousAuthentication enabled="true"/>
    </authentication>        
  </security>
</system.webServer>

现在对Test文件夹中的图像的任何请求都是未经身份验证的,并且所有内容都按预期工作,直到我为此文件夹引入了一个通用处理程序,如果在“Test”文件夹中找不到该文件,则会从后端存储中获取文件!匿名身份验证不再起作用。更新了下面的web.config文件 -

<location path="Test">
<system.webServer>      
  <handlers>       
    <add verb="*" path="Test"  requireAccess="None" name="Handler1" type="WebApplication1.Test.Handler1, Anonymous" />
  </handlers>
  <security>
    <authentication>          
      <anonymousAuthentication enabled="true"/>
    </authentication>        
  </security>
</system.webServer>

我使用fiddler检查了请求,如果我在配置中有处理程序部分,它会返回 HTTP / 1.1 401 Unauthorized 消息,但如果我从配置中删除处理程序部分,一切正常,我可以看到小提琴手中的有效回应。对这里可能出现什么问题的任何见解?

1 个答案:

答案 0 :(得分:0)

最后,我可以通过添加system.web修改位置配置来自行解决,以允许所有用户

<location path="Test">
<system.webServer>      
  <handlers>       
    <add verb="*" path="Test"  requireAccess="None" name="Handler1" type="WebApplication1.Test.Handler1, Anonymous" />
  </handlers>
  <security>
    <authentication>          
      <anonymousAuthentication enabled="true"/>
    </authentication>       
  </security>
</system.webServer>
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

相关问题