469,649 Members | 1,375 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Forcing ASP.NET processing of an arbitrary file

I have a simple project server which shares files from within our network.
The ASP.NET front end uses a database to authenticate users, and then based
on their permissions, reaches across the network to various project folders
and enumerates the files within. When clicked on, the file is retrieved and
streamed back across the network to the webserver and then back to the
requestor.

All of this works great; however, since the original call is to an ASPX
page, and the result is a data file (e.g. a word document, a tiff,
whatever), IIS doesn't get a chance to handle the file the way it normally
would.

The specific problem I'm facing is that I have certain HttpHandlers that
specially render certain document types. For example, I might have a
handler registered for the ".foo" document type. Because the actual IIS
request was formed like;

http://mysite/getfile.aspx?File=test.foo

IIS hands this off to the ASPX handler, which then goes and gets test.foo
and returns it.

How can I force IIS to also process the .foo file using the registered
HttpHander? I'm exploring three obvious approaches; and looking for advice
on the best decision and most straightfoward approach.

(1) Use an HttpModule. I've never worked with these; and I'm unfamiliar
with the capabilities, but investigations so far are leading me in this
direction as the "best long term choice".

(2) Find some way to get IIS to execute the HttpHandler processing on the
physical file stream I'm returning. I.e. I open a stream to the file data,
get the filename, and tell IIS to process and return this file as though it
were a regular request. I'm guessing this exists somewhere in the Server or
Request object models, but I haven't discovered anything obvious yet.

(3) Move all my custom HttpHandler code into my file requestor. This would
work, but it's a hack and prevents me from using third-party HttpHandlers in
the same way.

Thanks for any advice.

--Mwells

Nov 19 '05 #1
2 1155

May be another solution is to send content of your file as binary data and
specify the true content type in the HTTP Header like this:
Response.ContentType = "application/ms-word";
Response.AddHeader("Content-Disposition", "attachment;filename=word.doc");

See more in http://www.ondotnet.com/pub/a/dotnet...04/01/asp.html
or http://www.eggheadcafe.com/articles/20011006.asp

Lionel.
"MWells" <outbound__at_sygnal.com> a écrit dans le message de news:
ey**************@tk2msftngp13.phx.gbl...
I have a simple project server which shares files from within our network.
The ASP.NET front end uses a database to authenticate users, and then
based
on their permissions, reaches across the network to various project
folders
and enumerates the files within. When clicked on, the file is retrieved
and
streamed back across the network to the webserver and then back to the
requestor.

All of this works great; however, since the original call is to an ASPX
page, and the result is a data file (e.g. a word document, a tiff,
whatever), IIS doesn't get a chance to handle the file the way it normally
would.

The specific problem I'm facing is that I have certain HttpHandlers that
specially render certain document types. For example, I might have a
handler registered for the ".foo" document type. Because the actual IIS
request was formed like;

http://mysite/getfile.aspx?File=test.foo

IIS hands this off to the ASPX handler, which then goes and gets test.foo
and returns it.

How can I force IIS to also process the .foo file using the registered
HttpHander? I'm exploring three obvious approaches; and looking for
advice
on the best decision and most straightfoward approach.

(1) Use an HttpModule. I've never worked with these; and I'm unfamiliar
with the capabilities, but investigations so far are leading me in this
direction as the "best long term choice".

(2) Find some way to get IIS to execute the HttpHandler processing on the
physical file stream I'm returning. I.e. I open a stream to the file
data,
get the filename, and tell IIS to process and return this file as though
it
were a regular request. I'm guessing this exists somewhere in the Server
or
Request object models, but I haven't discovered anything obvious yet.

(3) Move all my custom HttpHandler code into my file requestor. This
would
work, but it's a hack and prevents me from using third-party HttpHandlers
in
the same way.

Thanks for any advice.

--Mwells

Nov 19 '05 #2
I'm actually doing that already, which keeps the client happy. If I hit a
Uri like;

http://mysite.com/getfile.aspx?FileID=123

And it pulls an Excel file from the database, the type and name are
appropriately specified so that the client recognizes it properly as an
Excel file.

Unfortunately this still excludes HttpHandlers from ASP.NET's processing
chain. If I have an HttpHandler installed that (for example) renders the
contents of the Excel file as HTML, that handler never gets called in the
execution chain.

Originally I thought it was due to the fact that .NET needs the Uri file
extension in order to associate the HttpHandler, so I've rewritten the
access Uri format using an HttpModule.

Now, I can request a file like...

http://mysite.com/files/data.xls

And the file data.xls is actually pulled from a database, mime-typed, and
returned to the client. All works well but the HttpHandler is still
excluded from the processing chain, and my handlers are never run.

I'm going off to think about this for a bit and then I'll fire off a new
post.

"Lionel LASKE" <ll****@c2s.fr> wrote in message
news:uH*************@TK2MSFTNGP11.phx.gbl...

May be another solution is to send content of your file as binary data and
specify the true content type in the HTTP Header like this:
Response.ContentType = "application/ms-word";
Response.AddHeader("Content-Disposition", "attachment;filename=word.doc");

See more in http://www.ondotnet.com/pub/a/dotnet...04/01/asp.html
or http://www.eggheadcafe.com/articles/20011006.asp

Lionel.

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by D. Alvarado | last post: by
4 posts views Thread by Dan Rawson | last post: by
6 posts views Thread by S P Arif Sahari Wibowo | last post: by
1 post views Thread by Mark Rae | last post: by
1 post views Thread by Xah Lee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.