Mapping classic asp pages to .net in IIS - asp.net

I'm trying to map requests for classic asp pages to be handled by .net, so that it runs through a custom httpmodule.
In IIS I have remapped asp requests to aspnet_isapi.dll - I'm sure I've done this bit right
Now in my test app I am getting this error:
Server Error in '/TestASPRedirect' 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 '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /testaspredirect/test.asp
Searching online for this error shows a load of people having problems with cassini, but this is not really relevant, I am testing this on both IIS 5.1 on XP dev machine, and have tested on IIS6 also getting the same error.
I have followed instructions for adding and registering a httphandler (see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308001), but I don't know what to put in the ProcessRequest routine to ensure the request gets passed on. What is the default .net httphandler, can I just map to this in web.config?: so something like:
<httpHandlers>
<add verb="*" path="*.asp" type="standard.nethttphandler"/>
</httpHandlers>
How do I tell asp.net that it needs to pass ASP requests on and not block?

Actually you are only one step far from the success. Adding following section to your Local website(or virtual directory) web.config file:
<configuration>
...
<system.web>
<compilation>
<buildProviders>
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>
<httpHandlers>
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true"/>
</httpHandlers>
</system.web>

It looks like the .asp extension is mapped to the HttpForbiddenHandler.
If you're using ASP.NET 1.1 then open the following file:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
If you're using ASP.NET 2.0 then open this file:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
Search for "path="*.asp"", then comment out that line. It'll like something like:
<!-- machine.config/ASP.NET 1.1-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler"/>`
<!-- web.config/ASP.NET 2.0-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler" validate="true"/>`

Locate the below file:
C:\WINDOWS\MICROSOFT.NET\FRAMEWORK\<FramworkVersion>\Config\web.config
where <FramworkVersion> is folder name:
open it in an XML editor .. (even notepad is fine)
and add below line :
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/>
under below XPath:
configuration/system.web/httpHandlers
replace the existing one!
Add below line:
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
under below XPath:
/configuration/system.web/compilation/buildProviders
Worked like gem for me :)

Related

web.Config Request Filtering, Block files that start with _

I'm dealing with a legacy classic asp app, and I would like to prevent files that start with underscore "" from being retrieved via a browser request. Ideally I want any file that starts with "" to show a 404 not found exception.
The reason being is I don't want to name my files with the .Inc extension because It makes it a pain in development as I lose syntax highlighting, intellisense, and other things I'm using in Visual Studio.
As this is running in IIS8, is there any way I can filter the request to block these files before the ASP handler processes the page?
Temporary Answer:
I mapped ASPClassic in the http handlers twice. First I mapped it to _*.asp. However I used an invalid dll for the asp dll, which will cause an error:
The page you are requesting cannot be served because of the ISAPI and CGI Restriction list settings on the Web server.
Which is a 404.2
Then I mapped the normal *.asp handler.
HttpHandlers don't pass to the next HttpHandler if it matches a request.. So the first HttpHandler to match the request is the one that get's used.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<remove name="OPTIONSVerbHandler"/>
<remove name="TRACEVerbHandler"/>
<remove name="ASPClassic"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="ASPClassic_No" path="_*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll2" resourceType="File" />
<add name="ASPClassic" path="*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="File" />
</handlers>
</web.Server>
Furthermore, server side includes still work on these files because SSI isn't request dependent.
If anyone knows a cleaner, non hacky way of doing this, I'm all ears!
I was using this asp file to do it prior to this:
<%
notFound_fullName = Request.ServerVariables("SCRIPT_NAME")
notFound_pathArray = split(notFound_fullName, "/")
notFound_fname = notFound_pathArray(UBOUND(notFound_pathArray))
If (InStr(1, notFound_fname, "_") = 1) Then
Response.Status ="404 Not Found"
Response.End
End If
%>
However, I ran into a scenario where I needed it to be included on a page that included it on the page, while also including it on the page that was being included.
E.g.
_cUser -> include 404handler code (alone with no other includes)
_baseWebService -> Include _AllClasses (includes 404 handler again)
Which won't work with option strict, becuase it's either redefining variables, or the variable isn't defined because option strict is on....

VirtualPathProvider doesn't (quite) work in production on IIS 7.5

I have been working on a project that has common bits of functionality, specifically I wanted to share the master file and related images/js/etc. To that end, the master page and its dependent files are all wrapped into a "global" DLL that is utilized by all "subprojects". This all worked great in development, but deployment yielded a surprise which seems to catch a lot of people off guard: VirtualPathProvider doesn't work when precompiled.
Now thanks to this blog post containing a workaround I was able to give another attempt at getting it to work. Regretfully, it still doesn't.
I opted to get rid of my Global.asax implementation and went with the blog post's AppInitialize approach:
public static class AppStart
{
public static void AppInitialize()
{
HostingEnvironment hostingEnvironmentInstance = (HostingEnvironment)typeof(HostingEnvironment).InvokeMember("_theHostingEnvironment", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
MethodInfo mi = typeof(HostingEnvironment).GetMethod("RegisterVirtualPathProviderInternal", BindingFlags.NonPublic | BindingFlags.Static);
mi.Invoke(hostingEnvironmentInstance, new object[] { new MasterPageProvider() });
}
}
Since the actual provider works in debug, I won't include it. If you would like to see it, don't hesitate to ask. Just wanted to keep the question as short as possible.
The interesting aspect to this whole situation is that production yields no errors about not being able to find the master page. To me, this means the provider is working, but for whatever reason the rest of the resources (js/css/etc) aren't being retrieved from the assembly properly.
So my question comes down to this: what are the reasons that this solution would work great in development, but not in production on IIS 7.5?
UPDATE 11/20/2011
Tried out David Ebbo's suggestion and had no results unfortunately. My web config looks something like this now:
<configuration>
<connectionStrings>
<clear />
<!-- ... -->
</connectionStrings>
<system.web>
<pages>
<controls>
<!-- ... -->
</controls>
</pages>
<compilation debug="true" targetFramework="4.0" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
UPDATE 11/21/2011
Just to verify my suspicion that the VirtualPathProvider was actually working, I commented out the third line (mi.Invoke(....) and redeployed the site. As I suspected, it now breaks due to not being able to find the MasterPage file. This issue appears to be related to only static files being delivered through the VPP.
IIS 7.5 will handle the static files itself. You need to put a line for each static file you want it to ignore in your web.config file to make them get routed through your VPP. See below for examples.
<system.webServer>
<handlers>
<add name="Images" path="*.png" verb="GET,HEAD,POST" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" resourceType="Unspecified" />
<add name="Stylesheets" path="*.css" verb="GET,HEAD,POST" type="System.Web.StaticFileHandler" modules="ManagedPipelineHandler" resourceType="Unspecified" />
</handlers>
</system.webServer>
Maybe the problem is that requests for static files are not going through ASP.NET by default in IIS.
Try whether turning on runAllManagedModulesForAllRequests in web.config helps. e.g.
<modules runAllManagedModulesForAllRequests="true" />
Take a look at this post. It explains how to get static files through a virtual path provider in IIS 7. I believe this will solve your problem.

HTTP Error 500.22 - Internal Server Error (An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.)

I receive this error when I view an application.
HTTP Error 500.22 - Internal Server Error (An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.)
.Net framework 2.0, 3.5 and 4 are installed and I am using SQL 2008. Can anyone tell me what the solution is for this error?
This issue is caused by the pipeline mode in your Application Pool setting that your web site is set to.
Short
Simple way Change the Application Pool mode to one that has Classic pipeline enabled.
Correct way Your web.config / web app will need to be altered to support Integrated pipelines. Normally this is as simple as removing parts of your web.config.
Simple way (bad practice) Add the following to your web.config. See http://www.iis.net/ConfigReference/system.webServer/validation
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
Long
If possible, your best bet is to change your application to support the integrated pipelines. There are a number of changes between IIS6 and IIS7.x that will cause this error. You can find details about these changes here http://learn.iis.net/page.aspx/381/aspnet-20-breaking-changes-on-iis-70/.
If you're unable to do that, you'll need to change the App pool which may be more difficult to do depending on your availability to the web server.
Go to the web server
Open the IIS Manager
Navigate to your site
Click Advanced Settings on the right Action pane
Under Application Pool, change it to an app pool that has classic enabled.
Check http://technet.microsoft.com/en-us/library/cc731755(WS.10).aspx for details on changing the App Pool
If you need to create an App Pool with Classic pipelines, take a look at http://technet.microsoft.com/en-us/library/cc731784(WS.10).aspx
If you don't have access to the server to make this change, you'll need to do this through your hosting server and contact them for help.
Feel free to ask questions.
In your web.config, make sure these keys exist:
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
I changed my web.config file to use HTTPMODULE in two forms:
IIS: 6
<httpModules>
<add name="Module" type="app.Module,app"/>
</httpModules>
IIS: 7.5
<system.webServer>
<modules>
<add name="Module" type="app.Module,app"/>
</modules>
</system.webServer>
Using VS2013 .net 4.5
I had this same issue.
The "Most likely causes" section on the error message page provided the most help. For me. It said "This application defines configuration in the system.web/httpModules section." Then in the "Things you can try" section it said "Migrate the configuration to the system.webServer/modules section."
<system.web>
<httpHandlers>
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" validate="false" />
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" validate="false" />
</httpHandlers>
<httpModules>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</httpModules>
</system.web>
into the system.webServer section.
<system.webServer>
<handlers>
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" name="ASPxUploadProgressHandler" preCondition="integratedMode" />
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
</handlers>
<modules>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</modules>
</system.webServer>
This worked for me:
Delete the originally created site.
Recreate the site in IIS
Clean solution
Build solution
Seems like something went south when I originally created the site. I hate solutions that are similar to "Restart your machine, then reinstall windows" without knowing what caused the error. But, this worked for me. Quick and simple. Hope it helps someone else.
I have a similar problem with IIS 7, Win 7 Enterprise Pack. I have changed the application Pool as in #Kirk answer :
Change the Application Pool mode to one that has Classic pipeline enabled".but no luck for me.
Adding one more step worked for me.
I have changed the my website's .NET Frameworkis v2.0 to .NET Frameworkis v4.0. in ApplicationPool
Personnaly I encountered this issue while migrating a IIS6 website into IIS7, in order to fix this issue I used this command line :
%windir%\System32\inetsrv\appcmd migrate config "MyWebSite\"
Make sure to backup your web.config
Set Application pool to classic .NET appool and make sure that Classic .Net apppool working on Classic managed piple line .

Timeline .NET Error

I worked with the simile timeline a few years back and I am excited to see that it has moved into the .NET world. However, when I get it all set up and try doing the example on this site, I get an alert with this error:
"Failed to load data xml from /TimelineData.ashx?Dataid=4123ea6c-3c1b-482c-b8f6-24a9c2fe7465&type=rss
Not Found
It does load the timeline itself properly, but it doesn't load any dates from my codebehind or rss feed from the example. However, the test project worked as expected when I downloaded the latest source code. I didn't notice a file with the name TimelineData.ashx anywhere in the latest source code, and yet it ran fine. If I copy the cc1:Timeline directly from the Default.aspx file in the TimelineTest project, I get the same results, the above popup dialog error.
It kind of seems like support on their site has fallen off, I was just wondering if anyone out there is familiar with this control and could give me a hand?
I had the same problem.
The fix! IIS versions 7 and greater
put the handler in the system.webServer, NOT the system.web.
EDIT: formating.
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ashx" verb="GET" path="TimelineData.ashx"
Type="TimelineNet.TimelineAjaxHandler, TimelineNet"/>
</handlers>
</system.webServer>
Its seems that you did not have setup the web.config to accrept the ashx for time line
Read this page for details
http://timelinenet.codeplex.com/wikipage?title=Installation&referringTitle=Home
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path=".ashx" type="TimelineNet.TimelineAjaxHandler, TimelineNet" validate="false" />
</httpHandlers>
</system.web>
</configuration>

Having jpg and gif handled by IsapiModule in IIS7

I'm struggling to get my HttpHandler to process requests for jpg and gifs.
I've gone to the website's Handler Mappings and added the following line:
Path: *.jpg,*.gif
State: Enabled
Path Type: Unspecified (I've also tried setting this to File)
Handler: IsapiModule
Entry Type: Local
Running through Visual Studio works, so I know its not my code. It also works on IIS6.
I've tried setting the app up in both classic and integrated mode.
Here's the appropriate Handler mappings specified in the web.config:
<add name="*.jpg,*.gif_*" path="*.jpg,*.gif" verb="*" type="ThumbnailGenerator,Utilities" preCondition="integratedMode,runtimeVersionv2.0" />
<add name="JPEG-GIF" path="*.jpg,*.gif" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
I fixed this by clearing out the handlers from web.config, then manually adding the using IIS: [Handler Mappings] -> [Add managed handler]
I'm not sure what difference this made, because the web.config looks pretty much the same as I had setup before, but now it works.

Resources