ASP.Net 4.0 - 如何从 ASHX 内访问 RouteData?
我的网站有一个处理程序 (FileDownload.ashx),用于处理所有文件下载请求。
我最近将我的网站迁移到 ASP.NET 4.0,它现在广泛使用路由。处理页面请求(aspx)时一切正常,但它不适用于我的处理程序 - 我遇到以下错误:
类型“.Handlers.FileDownload”不继承自“System.Web.UI.Page”。
这是有道理的,因为路由仅在页面中实现。
我需要采取哪些步骤才能同时使用路由和 .ashx?我希望能够从路线中提取 RouteData.Values
。
public class FileDownload : IHttpHandler
{
}
My web site has a handler (FileDownload.ashx) that deals with all file download requests.
I've recently migrated my site to ASP.NET 4.0, and it now uses routing extensively. Everything works fine when dealing with page requests (aspx), but it's not working with my handler - I encounter the following error:
Type '.Handlers.FileDownload' does not inherit from 'System.Web.UI.Page'.
This makes sense, as routing is only implemented in the page.
What steps do I need to take to be able to use routing and my .ashx together? I want to be able to extract RouteData.Values
from the route.
public class FileDownload : IHttpHandler
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来像是 IIS 问题。
如果您尝试使用 ASP.NET 开发服务器 (Cassini),这是否有效?
如果您使用的是 IIS6,则需要使用通配符应用程序映射 - 请参阅 此处。
您还需要根据任何 ASPX 页面创建路线,如下所示:
您做到了吗?如果是这样,我想说你的问题肯定是IIS的问题。
请参阅此处,了解有关适用于 IIS6 和 IIS7 的 ASP.NET 4 路由。
祝你好运!
Sounds like an IIS problem.
Does this work if you try and use the ASP.NET Development Server (Cassini) ?
If you're using IIS6 you'll need to use Wildcard Application Mappings - see here.
You'll also still need to create your routes as per any ASPX page, like this:
Have you done that? If so, i'd say your problem is definetely with IIS.
See here for a good article on ASP.NET 4 Routing for both IIS6 and IIS7.
Good luck!
我最终需要手工制作一个处理程序,但这很容易: http://haacked.com/archive/2009/11/04/routehandler-for-http-handlers.aspx
.Net 4.0 本身不支持 IHttpHandler 的路由处理。
I needed to hand craft a handler in the end, but it was easy enough: http://haacked.com/archive/2009/11/04/routehandler-for-http-handlers.aspx
.Net 4.0 does not natively support route handling for IHttpHandlers.