Url Routing is not working on IIS 6 - asp.net

Url Routing is not working on IIS 6. (using System.Web.Routing Namespace)
If i am running through VS 2008 then its working fine.
if i made virtual directory on IIS 6 then its not working.
its giving error 404 - file not found...
Thanks

By default, only files with extensions that are associated with ASP.NET (.aspx, .ashx etc) are sent to ASP.NET. You need to enable wildcard mapping to make sure that URLs to folders are processed (and thereby, routed) by ASP.NET:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/5c5ae5e0-f4f9-44b0-a743-f4c3a5ff68ec.mspx?mfr=true

Related

404 When Serving .cshtml in IIS 6

I'm trying to get an ASP.NET WebPages (Not MVC) site up and running with IIS 6, but I can't get it to serve .cshtml pages - It just spits back a 404 error every time. I've confirmed that it can serve .html and .aspx pages with no problem. So far, I've done the following:
Install ASP.NET 4.0 (aspnet_regiis -i)
Configure site to use ASP.NET 4.0 (aspnet_regiis -s ...)
Allow ASP.NET v4.0 Web Service Extension
Map aspnet_isapi.dll as handler for .cshtml files in Application Configuration (And as a wildcard mapping, no dice)
Add .cshtml to MIME types in Application Configuration
Ensure only ASP.NET 4.0 applications are in the app pool
Add <modules runAllManagedModulesForAllRequests="true" /> to web.config
Ensure that necessary .dll's are in the site's bin folder
Give "Everyone" group full control of the site folder and subfolders
I have a working site on the same framework that I set up a while back (And failed to document my process, lesson learned), so I tried exporting that site's config, creating a new site from file, and pointing it at the proper directory for the new site, but I'm still getting a 404.
I know that there are a whole lot of IIS/ASP.NET questions out there already, but every one I've seen is either not applicable to my situation (A lot of the MVC ones), or was solved by one or more of the things I've already tried.
Anyone have a clue as to what could be causing this?
CSHTML is templated page served by the Razor engine. Try opening an ASPX Page.
For serving cshtml, you need the Razor Engine configured.
Also, CSHTML are served differently based on the Routing configuration

Serving ASP.NET in Windows 7 IIS 7

I have worked with IIS 5.1 (XP) and 6 (Server 2003) but I am a little lost on IIS 7 (Windows 7).
I install IIS from windows component, created a new website testweb, added virtual directory, pointed it to where to serve pages from. Converted that to application. Now when I visis the site, it does go to the location and it lists all the files (I have enabled directory listing) but when I when I go to the test.htm file (I added) in the folder, I get this
HTTP Error 404.0 - Not Found The resource you are looking for has been
removed, had its name changed, or is temporarily unavailable.
The file is obviously there as it was listed in the directory. If I click on .aspx file I get this
HTTP Error 500.21 - Internal Server Error Handler "ASPX handler" has a
bad module "ManagedPipelineHandler" in its module list
One problem that I had was I could not save test.htm file directly in the directory (c:\program files\product\web) from Visual Studio, I had to save the file in documents folder and then copy it over as administrator.
My questions are:
Do I need to specify default handlers in II7 for ASPX pages? I heard they are not there by default. This would be in Hanlders section. I have already added one by the way.
Do I have to add MIME type for ASPX pages as well. They are not there be default. If I had one, I run into different errors.
Can anyone clarify on the two questions. Thanks
For #1, did you install the static file portion of IIS?
For #2, try re-registering ASP.Net 4.0 by running something like:
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i
(Depending your CPU you might want to use Framework64)
Also check that your app pool is targeting the 4.0 Framework and not the 2.0 Framework.

IIS returns 404 for ASP.NET MVC3 file (.cshtml)

I have standard ASP.NET 4 application. Inside this application there are also few razor (e.g. test.cshtml) files. ASP.NET application works however if I point browser to /test file (without extension). IIS (static file handler) returns 404.
The same application and even the standalone .cshtml files are working on local machine (with IIS7.5/Win7) and a server with (IIS7.5/Win2008R2), however it does not work the server with IIS7.0/Win2008.
MVC3 is installed on both machines, app pools on both machines are .NET 4.0 integrated.
How the .cshtml handlers works? When the IIS decides to use static file handler and when the .cshtml handler? What else should I check?
EDIT:
Clarification - I am not actually using whole MVC framework, it is just like plain-old .ASPX or PHP file. No controllers, no routes, no 'views'. I am using it for a simple script in addition to old ASP.NET application.
I think it is not a programming issue, since it works on local computer, but rather a configuration issue - the IIS on the Win2008 server might not be configured properly.
EDIT2:
(Machines with IIS7.5 works, only machine with IIS7.0 does not work. But I am not sure whether it is a problem of IIS version.)
EDIT3:
On my local computer where it works, I have not set any routing. TheCodeKing and Keith suggested that I need to have a routing somewhere. Maybe yes, but it is not in my application. It might be set by default somewhere in IIS configuration.
Do you have any hints where this 'implicit' routing could be found?
EDIT4:
Note: On all computers there is HttpForbiddenHandler for *.cshtml, since you cannot download the cshtml file. And there is also the TransferRequestHandler for *.. (Both are enabled.)
EDIT5:
I have found that on the servers, where it is working, I need to have any .cshtml file in the web root. If I remove the .cshtml from the web root and try to invoke any from a subdirectory it will not work.
EDIT6:
I tried that on another two machines: one with IIS 7.5 and another with IIS 7.0. On IIS 7.5 it works (plain install no configuration), but on IIS 7.0 it does not work.
How to make it work on IIS 7.0?
Yay! After several days of struggling I've found it! :))
One way to make it work on IIS 7.0 is to enable runAllManagedModulesForAllRequests:
<modules runAllManagedModulesForAllRequests="true" />
(Although, on IIS 7.5 it works even with the default value runAllManagedModulesForAllRequests="false".)
Don't ask me why:) Maybe someone can explain that.
Not sure if this is your particular problem, but it sounds like ASP.NET Web Pages isn't running (MVC 3 and up depend on Web Pages for Razor and other things). Sometimes things can get installed in orders that mess up some configuration of ASP.NET and IIS, which in turn could make it so Web Pages isn't running and no cshtml file will get executed.
Try running aspnet_regiis /i to clean it all up.
There is an hotfix for IIS7.0 available at: http://support.microsoft.com/kb/980368
I installed it today on windows 2008 SP2 (which requires an OS restart).
The behavior in IIS 7.0 is now similar than IIS 7.5
It fixed the problem on my side / without forcing:
<modules runAllManagedModulesForAllRequests="true" />
This is a better approach than running all modules for any request (even on css/images/...) which would cause unnecessary overload.
Are you sure that IIS has sufficient permissions to access the file under the /test directory?
This could cause some silly issues as I've found.
If this is an asp.net 4.0 web application, you will need to manually set up routes, create the appropriate controller(s), and make sure that your views (.cshtml files) actually exist in the /Views/ControllerName folder.
I would also recommend setting up your project to use IISExpress in your development environment to more closely match your web server. It's a great help when debugging these sort of issues.
As you aren't using MVC, you would need to set up routing, or rewriting using IIS rewrite module to expect /test to resolve to /test.cshtml. You won't get this behaviour without it.
e.g. something like this in your application start.
routes.MapPageRoute(
"extension-less paths",
"{view}",
"~/{view}.cshtml"
);
cshtml can work, if you set a web.conf.
You can think it is a html but with razor syntax.

IIS serves ASPX but not ASMX

Deployed an ASP.NET webforms application to IIS 6.0 64-bit server. Some associated DLLs are only available in 32-bit so I enabled 32-bit applications following these instructions. At first I was not able to view ASPX pages but I had forgotten to Allow the ASP.NET Web Service Extension. Sorted!
Recent testing has shown that a 404 is received when requesting ASMX web service files. From the IIS log the status code is:
404 0 2
Anyone have any ideas? I anticipate this being something silly like all 404s.
UPDATE 1
Not sure if this is related but the same error code is received when requesting PNG files. No problem serving JPG or GIF from the same folder... what!!!??? It is worth noting that if I change the extension of the image to JPG then it can be requested.
UPDATE 2
See answer below.
Okay found the problem.
C:\WINDOWS\system32\inetsrv\urlscan\UrlScan.ini did not have the PNG and ASMX extensions specified in the AllowExtensions list.
A nice quirk in our IIS server build!
Have you made sure that for .asmx file types, the handler is mapped to asp.net dll and that "check if file exists" is unticked within IIS?
I have changed connection pool to "Classic" from integtrated and it started working for me

ASP.NET Routing (in WebForms) not working when deployed under IIS, works in IDE

I have an ASP.NET web application(webforms,not MVC) developed in VS 2008 and I have implemented ASP.NET web forms URL routing by following this link https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx#postadlink
It works pretty good when I run it on the Visual studion IDE.But does not works when I created a site under my IIS (IIS 5.1 in XP) and deployed the same files there. I have set ASP.NET version as 2.0 in the Properties window of my application too.But does not work. Any idea why? Is there anything else to be setup?
Try using the following content from "Using ASP.NET MVC with Different Versions of IIS" # http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/mvc/tutorial-08-cs.aspx
Creating a Wildcard Script Map
If you don’t want to modify the URLs for your ASP.NET MVC application, and you have access to your web server, then you have an additional option. You can create a wildcard script map that maps all requests to the web server to the ASP.NET framework. That way, you can use the default ASP.NET MVC route table with IIS 7.0 (in classic mode) or IIS 6.0.
Be aware that this option causes IIS to intercept every request made against the web server. This includes requests for images, classic ASP pages, and HTML pages. Therefore, enabling a wildcard script map to ASP.NET does have performance implications.
Follow these steps to create a wildcard script map with IIS 6.0:
1. Right-click a website and select Properties
2. Select the Home Directory tab
3. Click the Configuration button
4. Select the Mappings tab
5. Click the Insert button (see Figure 4)
6. Paste the path to the aspnet_isapi.dll into the Executable field (you can copy this path from the script map for .aspx files)
7. Entery ".*" in the Extensions field
8. Uncheck the checkbox labeled Verify that file exists
9. Click the OK button
Check this System.Web.Routing RouteTable not working with IIS?
Are you trying to rewrite for a specific file extension, or are you trying to route all requests?
The reason I ask is because you may not have success with wildcard routing on IIS 5.1.
It works on IIS6 if you specify a wildcard map for the ASP.NET ISAPI filter.
Link with more info
IIS7 supports this via the integrated pipeline.

Resources