I have just moved an old classic ASP site from a win2003 IIS6 box onto a Win2008R2 IIS7 box, it's all working fine apart from one thing.
I had a little method which would let the user download a CSV of orders, the method is below:
sub DownloadOrders()
Response.clear
'Send headers for file name and content type changes
Response.AddHeader "Content-Disposition", "attachment; filename=orders.csv"
Response.ContentType = "application/text"
for I = 0 to ubound(theorderslist,2)
if I = 0 then
Response.Write("Order No,Date,Name,Address,Town/City,Country,Sub Total,Tax,Shipping,Total,Status" & vbCrLf)
end if
Response.Write("" & pOrderPrefix & "-" & theorderslist(0,I) & "," & theorderslist(3,I) & "," & theorderslist(5,I) & " " & theorderslist(7,I) & "," & Replace(theorderslist(8,I),","," ") & "," & Replace(theorderslist(12,I),","," ") & "," & theorderslist(13,I) & "," & theorderslist(14,I) & "," & theorderslist(15,I) & "," & theorderslist(16,I) & "," & theorderslist(4,I) & "," & orderStatusDesc(theorderslist(10,I)) & vbCrLf)
next
Response.End
end sub
Now if I click the link all I get is a 40开发者_JS百科4 error? I have even given the directory full modify permissions but still no luck? Any ideas what else I can try?
As above this has been working perfectly on the Win2003 box for years :(
I was about to ask a similar question but @stealthyninja put me on the right track with his stripped-down test code.
In my case, the culprit in my file turned out to be this:
Response.AddHeader "Content-Length", objFile.Size
Once I commented that line out everything worked fine, which lead me to this SO question about content-length which helped track down my real issue.
@leen3o: It sounds like the application/text
MIME type hasn't been defined in IIS. Included in this guide is how you can add it manually: http://www.iis.net/ConfigReference/system.webServer/staticContent/mimeMap
Update
Save the following stripped down copy of your Sub
to testcsv.asp
on the misbehaving server and access it directly. If the CSV file is produced with no errors, then what ever IIS7 doesn't like must lie elsewhere in your code and you'll need to please paste a little more of it so we can help you debug it.
Response.AddHeader "Content-Disposition", "attachment; filename=orders.csv"
Response.ContentType = "application/text"
Response.Write("Order No,Date,Name,Address,Town/City,Country,Sub Total,Tax,Shipping,Total,Status" & vbCrLf)
Response.End
Here are some useful articles
http://www.alexthissen.nl/blogs/main/archive/2008/02/18/running-classic-asp-on-iis-7.aspx
http://technet.microsoft.com/en-us/library/cc753918%28WS.10%29.aspx
What is the filetype extension on the script that produces the CSV file?
IIS will not serve file types for which it does not have a MIME type registered and instead will return a 404
Additionally as stealthyninja states if the application/text
MIME type is not mapped then IIS will also not serve the file
Just checked on my IIS7 instance on my Windows Server 2008 dev machine and it doesn't have application/text registered by default as far as I can see.
精彩评论