File redirection in Windows hosting - How?

I want to have a script (ASP or ASP.NET) named "file.exe" that logs attempts to download the actual file "file.exe".

i.e. The script logs the attempt to download the file and then does a server-side redirect to the actual file and forces a download.

The purpose is to make the file look like it is a direct download and not a redirection script.

Normally, I would make the "script" file a zero length file and create a redirection to an ASP or ASP.NET file in the IIS Manager, which would then run, do it's job, and return the actual "file.exe".

Is there anyway to do this (or something similar) without issuing a support ticket? I can't find anything in H-Sphere.

Thanks for any help
 
Renegade said:
I want to have a script (ASP or ASP.NET) named "file.exe" that logs attempts to download the actual file "file.exe".

You could create a dl.asp page, that gets called as dl.asp?f=file.exe. Then the ASP page could append a text line to a text log file logging the request, and then open the EXE file and spit out back at the user. You should have to include validation of the file name requested to ensure it's not one of your asp files, but is one of your exe files.

I haven't done this, so don't ask me how exactly, but I'm confident this is possible.
 
You can add a redirect using H-Sphere, but the webserver will send a redirection response (to your script), which will then send the file.

That method is not completely transparent for anyone looking at it at the protocol level, so I don't know if it suits your purpose. From the Quick Access screen, click Redirect URL.

On one of my own sites I now have the .CGI extension linked to PHP, because I ported an auto-update checker for a program of mine which didn't bother to support URL redirection 8) I suppose that could work for .exe as well, but you can't set it up like that using ASP in H-Sphere.
 
ASP:

Code:
<%
  [color=Green] 'Declare variables[/color]
  [color=Blue] Dim[/color] strFolder [color=Green] 'Folder[/color]
  [color=Blue] Dim [/color]strFile [color=Green] 'File[/color]
  [color=Blue] Dim[/color] objStream [color=Green] 'Stream object (to force a download)[/color]
  [color=Blue] Dim [/color]objFSO [color=Green] 'File System Object[/color]
   
   strFolder = Request.QueryString("Folder") [color=Green]'folder on servers harddrive. Should be without the trailing slash[/color]
   strFile = Request.QueryString("File") [color=Green]'File inside the folder[/color]
   
  [color=Green] 'Create the file system object[/color]
  [color=Blue] Set[/color] objFSO = Server.CreateObject("Scripting.FileSystemObject")
   
  [color=Green] 'Checck if folder and file exists[/color]
  [color=Blue] If[/color] objFSO.FolderExists(Server.MapPath(strFolder)) = [color=Blue]False Then [/color]Response.Redirect("[color=Red]ERROR PAGE[/color]")
  [color=Blue] If[/color] objFSO.FileExists(Server.MapPath(strFolder & "\" & strFile)) = [color=Blue]False Then[/color] Response.Redirect("[color=Red]ERROR PAGE[/color]")
   
  [color=Green] 'Check folder[/color]
  [color=Blue] If [/color]Left(strFolder, [color=Red]LENGTH OF THE NAME OF YOUR DOWNLOADS FOLDER[/color]) <> "[color=Red]YOUR DOWNLOADS FOLDER NAME[/color]" [color=Blue]Then[/color] Response.Redirect("[color=Red]ERROR PAGE[/color]")
   
  [color=Green] 'Load the file and send it to the browser[/color]
  [color=Blue] Set [/color]objStream = Server.CreateObject("ADODB.Stream")
   objStream.Open
   objStream.LoadFromFile(Server.MapPath(strFolder & "/" & strFile))
   
   Response.ContentType = "xxx/xxx"
   Response.AddHeader "content-disposition", "attachment; filename=" & strFile
   Response.BinaryWrite objStream.ReadText
   
  [color=Green] 'Clean up[/color]
   objStream.Close
  [color=Blue] Set [/color]objStream = [color=Blue]Nothing[/color]
  [color=Blue] Set [/color]objFSO = [color=Blue]Nothing[/color]
   %>

Please tell me if it doesn't work
 
I don't think the ASP code was the problem though, the problem was getting that code to execute :)
I don't see how that's possible without a redirection, but that isn't a problem in most cases.
 
LegalAlien said:
:D That is hilarious!!!!!! I remember seeing Atuls comment, but I didn't see Yash's - did he also correct himself? What exactly did he mean??!!!

He meant that Win5 and Win6 were more stable servers because they were running Windows 2000 :)
No, he never corrected himself, but from the thread it was pretty clear what he meant..
Gotta love out of context quoting 8)

This is not really the right forum for it, but if anyone feels deeply hurt or wrongly treated by these or any possible future quotes, let me know and I'll keep them to myself :D
 
SubSpace said:
I don't think the ASP code was the problem though, the problem was getting that code to execute :)
I don't see how that's possible without a redirection, but that isn't a problem in most cases.
okay..

but I see I forgot the most important part too - the logging LOL

I will do that if an ASP scipt really is what HE(not you) need



by the way, good sig SubSpace LOL
 
I think the redirection scenario in the H-Sphere control panel seems best.

The ASP script really isn't necessary as a simple "response.redirect" works fine.

All the other stuff, whether text file or database is not really too relevant as it's much easier.

I guess that if anyone takes a close look at it the http level, then they might figure it out. I'm not too worried about that, although you were right in guessing that I wanted to avoid that scenario if possible. I'll just have to wager on human nature being lazy :p

Thanks for the input!
 
In the above 301 redirect example, you need to change the Location to the URI of your new page. Include the full URI path unless you are redirecting to a root level page (index.asp, default.asp, etc.). If you are setting up a 301 redirect for a root level page, keep the URI short and without the index.asp file name.
for example… “
Once you’ve included the above code at the top of your old-page.asp, you should crosscheck that it is returning the proper server header response using tool to check Server header content.
Doing so, we instruct the spiders to update their index and replace the old URI (old-page.asp) with the new URI (new-page.asp).
 
Back
Top