File extension problems with classic ASP - asp-classic

I am running a classic ASP website where my online users can attach files to the internal message system. But whenever they upload an attachment with more then 3 characters in the file extension, the server gives me a 404.
Files like mypicture.jpg works fine, but files like mydocument.docx doesn't work?
Any suggestions?

IIS6 will only serve documents where the file extension is mapped to a mime type in the mime map property for the server or the site. In order to serve the more recent Office 2007 document types you will need to add extra mappings.
There are a number of places where you can find a list of these new mime types.
This is a simple one; from Office 2007 mime types for IIS:
.docm,application/vnd.ms-word.document.macroEnabled.12
.docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotm,application/vnd.ms-word.template.macroEnabled.12
.dotx,application/vnd.openxmlformats-officedocument.wordprocessingml.template
.potm,application/vnd.ms-powerpoint.template.macroEnabled.12
.potx,application/vnd.openxmlformats-officedocument.presentationml.template
.ppam,application/vnd.ms-powerpoint.addin.macroEnabled.12
.ppsm,application/vnd.ms-powerpoint.slideshow.macroEnabled.12
.ppsx,application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pptm,application/vnd.ms-powerpoint.presentation.macroEnabled.12
.pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation
.xlam,application/vnd.ms-excel.addin.macroEnabled.12
.xlsb,application/vnd.ms-excel.sheet.binary.macroEnabled.12
.xlsm,application/vnd.ms-excel.sheet.macroEnabled.12
.xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltm,application/vnd.ms-excel.template.macroEnabled.12
.xltx,application/vnd.openxmlformats-officedocument.spreadsheetml.template
Adding all mime-types to IIS in one step is very simple:
The easiest way to do this is stopping IIS and editing the metabase
XML file (C:\WINDOWS\system32\inetsrv\MetaBase.xml) using a text
editor. Search for the <IIsMimeMap Location="/LM/MimeMap" /> element
and append the lines above to the MimeMap attribute

The server probably has no mime-type defined for docx and such file extensions.

Related

Force file download in a browser using ASP.Net MVC when the file is located on a different server without downloading it on my server first

Here's what I would like to accomplish:
I have a file stored in Windows Azure Blob Storage (or for that matter any file which is not on my web server but accessible via a URL).
I want to force download a file without actually downloading the file on my web server first i.e. browser should automatically fetch the file from this external URL and prompts the user to download it.
Possible Solutions Explored:
Here's what I have explored so far (and why they won't work):
Using something like FileContentResult as described here Returning a file to View/Download in ASP.NET MVC to download the file. This solution would require me to fetch the contents on my server and then stream from my server to the browser. For this reason this solution won't work.
Using HTML 5 download attribute: HTML 5 download attribute would have worked perfectly fine however the problem is that while it is really a very neat solution, it is not supported in all browsers.
Changing the file's content type: Another thing I could do (at least for the files that I own) to change the content type property of the file to something that the browser wouldn't understand and thus would be forced to download the file. This might work in some browsers however not in all as IE is smart enough to go beyond the content type and sees the file's content to determine the content type. Furthermore if I don't own the files, then I won't have access to changing the content type of the file.
Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file.
Is this something which can be accomplished? If yes, then any ideas how I could accomplish this?
Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file [without exposing the URL of the file to the client].
You can't. If the final URL is to remain hidden, your server must serve the data, so your server must download the file from the URL.
Your client can't download a file it can't get the URL to.
You can create file transfer WCF service (REST) which will stream your content from blob storage or from other sources through your file managers to client browser directly by URL.
https://{service}/FileTransfer/DownloadFile/{id, synonym, filename etc}
Blob path won't be exposed, web application will be free from file transfer issues.

HTTP Error 404.3 - Not Found ... while downloading .dae files on ASP.Net

When I try to access a file extension .dae on IIS server... I get this error:
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
Looks like I am not able to configure something on my IIS Server. Can somebody please direct me to the right places. I am using Visual Express 2012 for web.
Since directory browsing is disabled for you, only few file types are accessible for the client,
like scripts and images.
In order to allow other file types, try this link. don't forget to replace the dmg with dae of course.

How does people make ASP.NET page in URL with html file name?

I seen an ASP.NET application, in the URL is saying:
http://xxxxxxxxx/FILENAME.html?xxxx=xxx
How come it is html file? But not aspx file? How did they do it?
I heard from my manager that's an ASP.NET project he outsourced.
Sometime I seen people with their web page is ended in .html too, but obviously that is generated dynamically...
Files ending with .html are optional. These are static HTML-pages without any code-behind and can be included as part of any web application. They are not parsed and compiled by the server but rather just sent as good old predefined HTML.
You can also configure the web server so that it routes requests with different endings through the ASP.net rendering engine. This way you can keep the widely recognized ending .html and still have dynamic page generation.
The file extension is not necessarily tied to the execution engine. You can make ASP.NET process .aspx, .html, .htm, .bob, .foobar, .css, etc.
There are multiple of ways to do this:
In IIS manager, set the file extension mapping for .html to point to ASP.NET. If you're using MVC, you can handle this via routing.
Use a rewrite engine to map anything with a .htm* extension to .aspx
There are probably other ways, but these are the most direct.
Also, the .html extension doesn't mean that the file was dynamically generated.
You can use URL rewriting. There are a lot of different rewriters most popular being the URL rewrite module ( http://www.iis.net/download/urlrewrite ) and the built in (in ASP.NET 4.0) Routing Engine ( http://msdn.microsoft.com/en-us/library/cc668201.aspx ).
The URL Rewrite module is external to your application and it translates incoming URLs to regular .aspx URLs. You are responsible for generating the links with .html. It is good if you are adding it to an existing application.
The built in routing can generate urls based on routes and is configured in Global.asax (usually) with code.
Right click on the project.
Add new...
pick the HTML file type.
Some people prefer to use a different extension (or even none at all) in order to hide the technology used to develop the site.
Bear in mind that you would have to properly configure IIS to let the .net engine handle the .html file types.

Creating a robots.txt for an ASP.NET MVC site

I'm creating a robots.txt file for my website, but looking through my project structure, I'm not sure what to disallow.
Do I need to disallow standard .NET MVC directories and files like /App_Data, /web.config, /Controllers, /Models, /Global.asax? Or will those not be indexed already?
What about directories like /bin and /obj?
If I want to disallow a page, do I disallow /Views/MyPage/Index.cshtml, or /MyPage?
Also, when specifying the sitemap in the robots.txt file, can I use my Web.sitemap, or does it need to be a different xml file?
'robots.txt' refers to paths as they are publically seen from Web crawlers.
There's nothing particularly special about a crawler: it merely uses HTTP to request pages from your site precisely like a user does.
So, given that your MVC site is properly configured, files like /web.config or the paths you mention won't be visible to the outside world as neither IIS nor your application will be configured to serve them. Even if it was pointed to those files the spider would receive a 404 Not Found and continue.
Similarly, your .cshtml or .aspx content files won't be seen with those extensions. Rather, a Web crawler will see precisely what you'll show to users.

IIS - wont serve an .ini file

I have a .ini file in the virtual directory of IIS. When i try to open the same in IE i get file not found HTTP 404 error.
http://www.virtualdirectoryname/sample.ini
Any inputs.
Please suggest some solution.
Thanks,
Karthick
By default, IIS will only serve files for which the extension matches a defined MIME type. See the following support article for reference - http://support.microsoft.com/kb/326965
To allow .ini files to be downloaded, follow the steps from the KB article linked above:
Open the IIS Microsoft Management Console (MMC), right-click the local computer name, and then click Properties.
Click MIME Types.
Click New.
In the Extension box, type the file name extension that you want (in this case, .ini).
In the MIME Type box, type application/octet-stream.
Note: this is specific to IIS 6 or IIS 5.x - The process is slightly different for IIS 7.x

Resources