Using URL Routing for Web Forms with .ashx files
Posted
by RandomBen
on Stack Overflow
See other posts from Stack Overflow
or by RandomBen
Published on 2010-03-22T17:12:49Z
Indexed on
2010/03/22
17:21 UTC
Read the original article
Hit count: 563
I am developing a .NET 3.5 Web Forms based website that uses URL Routing. So far I have created a few routes and I have had no issue. I now have a .ashx file that is going to handle sending .pdf files from a table in SQL Server to the website when someone clicks on a link. Normally when I create a Handler it would look like this:
return BuildManager.CreateInstanceFromVirtualPath("~/ViewItem.aspx", typeof(Page)) as Page;
For my .ashx file I tried:
return BuildManager.CreateInstanceFromVirtualPath("~/FileServer.ashx", typeof(Page)) as Page;
This doesn't work though because fileserver.ashx is not a page so casting it as typeof(Page)) as Page is going to fail. What do I cast the VirtualPath as instead of Page or is there some other way I should be doing this.
© Stack Overflow or respective owner