IIS Handler Mappings for classic asp page include(.inc) file - asp-classic

I am mirgranting a classic ASP site to newer version of Windows server hosted in IIS 10.
When loading the default.asp page, I found in the browser's developer tool, network tab it says helpers.inc file could not be find. But it is in the same folder with the default page.
The helpers.inc file is invoked in the default.asp page by this code:
<script src="helpers.inc" language="VBScript" defer="true"></script>
If I try to access the helpers.inc file from browser, I will get this error:
HTTP Error 404.3 - Not Found
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.
Most likely causes:
•It is possible that a handler mapping is missing. By default, the static file handler processes all content.
•The feature you are trying to use may not be installed.
•The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.)
•If ASP.NET is not installed.
I tried add a handler mapping for *.inc file using the %windir%\system32\inetsrv\asp.dll executable, but it doesn't seem working. Gives me a new error:
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.
Most likely causes:
•The request matched a wildcard mime map. The request is mapped to the static file handler. If there were different pre-conditions, the request will map to a different handler.
I am wondering what I need to let the include(.inc) file can be recognized/read by the asp page?

If this line is how it appears in the migrated code (without any modification)
<script src="helpers.inc" language="VBScript" defer="true"></script>
then one thing is clear.
This isn't a SSI (Server Side Include).
The tag defines a file with an .inc extension as a Client Side VBScript. At the moment though, you haven't told IIS that .inc is a file type it is allowed to serve as text/vbscript.
Note: Having client-side VBScript defined in the page will severely limited cross browser compatability because VBScript is only supported in older versions of Internet Explorer.
Why 404.3?
The reason for the 404.3 is because IIS blocks unknown file types. To fix this you need to add a MIME type mapping in IIS which I wouldn't usually recommend as .inc is sometimes used as an extension for SSI files, but as we have debunked that theory mapping the MIME type is the way go.
Why it's not an SSI
There are only three ways to run server-side script in a Classic ASP page;
Using processor tags
<%
...
%>
Using script tags with the runat="server" attribute.
<script language="VBScript" runat="server">
...
</script>
Adding an SSI using the #include directive.
<!-- #include virtual = "somefile.asp" -->
Useful Links
Answer to IIS 7.5 doesn't run *.inc as ASP Classic (argument for not using .inc extension for client-side script).
Answer to difference between mime types and extension filtering on IIS?.

Include works, but Lankymart's answer is correct.
I created a helpers.inc file:
Sub MakeAMsg(MsgText)
MsgBox MsgText
End Sub
I used Include and kept the .inc extension:
<script language=VBS>
<!--#include file=helpers.inc-->
makeamsg("This Used Include")
</script>
It works. I renamed the .inc with a VBS extension:
<SCRIPT language=VBS src=helpers.vbs></SCRIPT>
<script language=VBS>
makeamsg("This Used Script tags with vbs extension")
</script>
And that works, too.
I checked my server and by default .vbs was set to a mimetype of text/vbscript. (I'm in the middle of setting up another where I haven't changed anything, and it has this mapping, as well.)
So using #include does work, but either changing the extension to .vbs or adding a mimetype that duplicates the .vbs mime type would be better.

Related

web.config file not there in the root(/) directory

I was trying to run a .cshtml file but it gave an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /index.cshtml
So I searched for the solution and found that I had to edit the web.config file which is in the root directory(here it is My Site), but there is no file like that there there is only an index.cshtml which I had created.
I searched even the IIS and the IIS Express folders in Programs Files\ but there was no file like that?
If you are using WebMatrix, maybe your mistake was the starting point choice.
If you want to create a new Web Pages site you must start from a template in the Template Gallery of WebMatrix. Pay attention that the Empty Site template differs from the Empty Site option outside the Template Gallery because the first holds the files (binaries, packages and the web.config too) that are needed.
As the server error suggests, .cshtml files are not served, the reason for this is because they are server-side files that make up your application, they are just one piece of a much bigger picture.
If you launched your web application in debug mode and the URL in the browser was something like http://localhost:2932/Views/Home/Index.cshtml, just drop the /Views/Home/Index.cshtml part of the URL.

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.

IIS 7.5 doesn't run *.inc as ASP Classic

I'm setting up an ASP Classic website on Win7 x64, I have done the usual trick (Add site as Application to enable global.asa, use Classic pipeline App Pool, Enable 32-bit Applications: True, Load User Profile: False, Enable Parent Paths: True, give Everyone full access to site files, use odbc 32), and the site is up and running for *.asp files. However, I have some files named as *.inc under Includes directory, and IIS doesn't seem to be able to process them.
When I try to access http://localhost//includes/myfile.inc, I got:
HTTP Error 404.3 - Not Found
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.
I tried to add a script map in Handler Mapping, similar to the one for *.asp: Request Path = *.inc, Executable = %windir%\system32\inetsrv\asp.dll, Invoke handler only if request is mapped to File, and in the ordered list this new mapping is on top. Now I got this error when request .inc:
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.
Any ideas?
Why are you trying to load .inc files in the browser? This is not normal behavior. Those files are meant to be included in other files, such as the ASPs.
Blocking those files from being requested is protecting you from revealing your source code, which is what would happen if IIS did serve those files; it would just output their contents verbatum.

IIS Server Side Includes doesn't process ColdFusion

How can I use the Server Side Includes module in IIS to include and process a ColdFusion file from a .htm file? I'm currently doing something like this in my html file:
<!--#include virtual="navmenu.cfm"-->
This includes the raw contents of the navmenu file. I need it to execute the ColdFusion code and return the output of that process rather than including the raw ColdFusion code.
This same syntax works properly in Apache.
Are you just trying to avoid the CFM extension in the URL?
You can't use SSI to include a CFM files into a static HTM file. You can configure IIS to send HTM files to the CF server to be parsed. This would allow you to use CFINCLUDE inside any HTM file.
Alternately, you can use ajax from your HTM file and load the parsed CFM content into a DIV.
If you can't make the top page appear to be a cfm to the outside have you thought about using the URL Rewrite Module for IIS? That way you could just make certain files cfms with some explicit htm to cfm rewrite rules but leave all others unprocessed. Beyond that I think there may not be an elegant answer since you are mixing static and dynamic content.
On your comment about ajax - personally I don't find anything tedious about using ajax but then again jquery spoils you...
<div id='menuhere'></div>
$.get('navmenu.cfm', function(data) {$('.menuhere').html(data); });
Accomplishes the same thing as the SSI plus (assuming jQuery is cached) you get faster main content page loads to boot.
If you are using a Coldfusion page it is:
<cfinclude template="navmenu.cfm">
If you are using another type of page you will need to put that content in an IFRAME
<iframe src="navmenu.cfm"></iframe>
The question is if you have Coldfusion technology available on the server, why not change that page to a .cfm page and use the above example?

Resources