【发布时间】:2017-01-18 17:12:51
【问题描述】:
我有一个可以直接从 URL 访问的文件目录
例如
http://website.com/DirectoryName/folder/downloadpdf.pdf
我需要控制谁可以访问这些文件,所以我创建了一个 ASHX 处理程序,以便检查用户的权限。
但是,当我访问 http://website.com/DirectoryName/ 时,处理程序不会被调用。
我相信这与我的配置有关,我有
<location path="DirectoryName">
<system.webServer>
<handlers>
<add name="PSHandler" path="DirectoryName/*" verb="*" type="ProjectName.PSHandler"/>
</handlers>
</system.webServer>
</location>
不同的方式 - IIS 6?
<location path="DirectoryName">
<system.web>
<httpHandlers>
<add path="DirectoryName/*" verb="*" type="ProjectName.PSHandler, PSHandler"/>
</httpHandlers>
</system.web>
</location>
上面有什么问题吗?
ashx 文件
<%@ WebHandler Language="VB" Class="PSHandler" %>
Imports System
Imports System.Web
Public Class PSHandler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/plain"
context.Response.Write("Hello World")
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
仅供参考,这是通过使用 IIS Express 在本地运行
谢谢
【问题讨论】:
-
您的解决方案中有
ashx处理程序吗?或者你有一个实现ihttphandler的通用类吗? ashx 通用处理程序需要在其自己的实际 url 上请求......或者这至少是 ashx 处理程序的正常用例。无论如何,您的配置中是否有额外的DirectoryName级别? -
是的,我的应用程序根目录中有
PSHandler.ashxfile。是的,它确实实现了ihttphandlerDirectoryName 也在根目录中,所以它在 .com/ 之后
标签: asp.net httphandler ashx virtual-directory