Diagnosing 404 errors on IIS 7 and ASP.NET MVC - asp.net

I have an mvc app developed and tested with Cassini. Deployed to my site on GoDaddy, and the default page comes up fine. Click to log in, and I get a 404.
I'm running under IIS 7 there, so this is unexpected. My routes are pretty plain:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Public", action = "Index", id = "" }
);
routes.MapRoute(
"Report1",
"Report/{action}/{start}/{end}",
new { controller = "Report", action = "Index" }
);
routes.MapRoute(
"Report2",
"Report/{action}/{start}/{end}/{idList}",
new { controller = "Report", action = "Index" }
);
Any idea what might be going on or how I can troubleshoot this?

Are you running in IIS7 integrated mode?
Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6).
Also make sure your Web.config <system.webServer> tag is configured correctly.

Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.
<system.webServer> <!-- Rather do NOT use this -->
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Instead add the MVC routing module
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>

Tried everything, I had to set my web config like this, to make it work.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

I had the same problem, I uploaded the controller, web.config and other classes but I forgot to upload the bin folder.
After I uploaded the bin folder, it worked!

Related

IIS 7.5 and handler mapping

I want to redirect all urls like http://domain.com/xxx/yyyyy.html to my ASP.NET MVC application. I opened Handler Mappings for my site and added the following rule:
in web.config it look like:
<system.webServer>
<handlers>
<add name="HTML Rewriter" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
</handlers>
</system.webServer>
in routes of asp.net mvc application:
routes.MapRoute(
"xxx", // Route name
"{ext}/{filename}.html", // URL with parameters
new { controller = "Mycontr", action = "Index" } // Parameter defaults
);
but when I try to open this url I got 404 file not found. Why? It works locally under IIS express
After adding handler you must have to execute it...
Goto edit feature setting...select execute option...
and also add this handler to ISAPI & CGI restrictions at server level..it will resolve the issue

ASP.net MVC4 WebApi route with file-name in it

I'm trying to get the following (and similar) urls to work in my ASP.net MVC4/WebApi project:
http://127.0.0.1:81/api/nav/SpotiFire/SpotiFire.dll
The route responsible for this url looks like this:
config.Routes.MapHttpRoute(
name: "Nav",
routeTemplate: "api/nav/{project}/{assembly}/{namespace}/{type}/{member}",
defaults: new { controller = "Nav", assembly = RouteParameter.Optional, #namespace = RouteParameter.Optional, type = RouteParameter.Optional, member = RouteParameter.Optional }
);
It works just fine if I remove the . in the file-name, or if I add a slash behind the URL, but that also means I can't use the Url.Route-methods etc. The error I get is a generic 404-error (image below).
I've tried adding <httpRuntime targetFramework="4.5" relaxedUrlToFileSystemMapping="true" /> to my web.config, and I've also tried adding
<compilation debug="true" targetFramework="4.5">
<buildProviders>
<remove extension=".dll"/>
<remove extension=".exe"/>
</buildProviders>
</compilation>
And none of it seems to work. So my question is basically, how can I get this URL to work, and map correctly?
You could add the following handler to the <handlers> section of your <system.webServer>:
<add
name="ManagedDllExtension"
path="api/nav/*/*.dll"
verb="GET"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"
/>
This will make all requests containing .dll be served through the managed pipeline. Also notice how I have limited them only to the GET verb to limit the performance impact.
Found it. What's needed is this (and maybe some of the things I've added above in the original post):
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
My trade off was to append /end to the end of route. .'s are ignored before the last /.
The equivalent URL would be http://127.0.0.1:81/api/nav/SpotiFire/SpotiFire.dll/end.
The benefit being that you don't get a performance hit on your assets.

Set default webpage for website on Microsoft Windows Azure

I recently set up a website on azurewebsites.net.
But when I go to the url http:/website.azurewebsites.net/
it doesn't load.
But when I go to http:/website.azurewebsites.net/home.aspx it loads.
What I want is that
if a user goes to http:/website.azurewebsites.net/ it loads with the home.aspx content or get redirected to http:/website.azurewebsites.net/home.aspx
This doesn't work
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Default.aspx" />
</files>
</defaultDocument>
</system.webServer>
Sorry here's the actual link http://rathgarfantasyhockey.azurewebsites.net/default.aspx which works fine, but when you go to http://rathgarfantasyhockey.azurewebsites.net HTTP error 404, The resource cannot be found is displayed.
Can anyone help??
According to this blog post: http://blogs.msdn.com/b/cesardelatorre/archive/2010/07/22/how-to-set-a-default-page-to-a-windows-azure-web-role-app-silverlight-asp-net-etc.aspx
<defaultDocument>
<files>
<clear/>
<add value="Default.aspx"/>
</files>
</defaultDocument>
Should Work. Or you could Type to Url map it. To do that check out http://msdn.microsoft.com/en-us/library/cc668201.aspx
If you are using MVC or Web API, add the following line in RegisterRoutes():
routes.IgnoreRoute("");
This solved my problem. Hope it helps you.
If you app is a MVC application, it looks for the default controller instead of default pages.
So you must map a route in RouteConfig. In my case,I wanted to load the site with an index.html page, so I did:
RouteConfig.cs file:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
And in my HomeController, Index Action, write this code:
public ActionResult Index()
{
return Redirect("/index.html");
}
This works fine in Azure with a Shared Site. I hope this will help you.
Do you have a typo?
You have:
<add value="Default.aspx" />
But you said that your "home page" that works is /home.aspx.
If you want for /home.aspx to be displayed when the user goes to http:/website.azurewebsites.net/, then I can think of several ways for you to accomplish that.
Since you have Default.aspx as your defaultDocument, you can rename home.aspx to Default.aspx and when someone goes to http:/website.azurewebsites.net/ the contents of Default.aspx will be displayed.
If you need to keep home.aspx named as home.aspx for some reason, then as you requested if you want for http:/website.azurewebsites.net/ to redirect to /home.aspx then create a file called Default.aspx in the root directory and edit it to contain Response.Redirect("home.aspx", false);. A complete example for this type of page is available at http://msdn.microsoft.com/en-us/library/a8wa7sdt(v=vs.80).aspx.
Update:
Try adding enabled="true" to your defaultDocument XML tag. See the example below from http://www.iis.net/ConfigReference/system.webServer/defaultDocument
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="home.html" />
</files>
</defaultDocument>
</system.webServer>

ASP MVC 2 handlers for extensionless urls in IIS 7.5 not working

I have a project with a HttpHandler that's supposed to execute when an extensionless url like this localhost/foo/bar is requested. I got this properly working on a local Visual Studio development server (by using <httpHandlers> in <system.web> instead of <system.webServer><handlers>) but this functionality doesn't work when deployed to IIS 7.5 (Standard 404 error: http://i.imgur.com/YuNjT.jpg). This issue is not restricted to extensionless URLs (I might add any extension at the end and the issue remains) but my desired functionality is to use extensionless url in this scenario. I googled some information that extensionless URLs may cause some issues that's why I mention it here. The AppPool is set to Integrated. I did aspnet_regiis.exe -i. I have Http Redirection feature installed on the IIS server. Here's my handlers config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="FileDownloadHandler" path="/Home/Files/*" verb="*" type="MvcApplication1.FileDownloadHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
</handlers>
<directoryBrowse enabled="true" />
</system.webServer>
And here's my routing setup:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("home/files/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
I'm guessing the code is fine but something's off with my IIS configuration. Can anyone guide me in the right direction? I've googled for days now and I couldn't find a solution that helped me. Here's a sample project (works on local VS dev server but not on my IIS):
http://mapman.pl/MvcApplication1.zip
When you build (and deploy to your local IIS) the above solution try requesting an url like this: http://localhost/MvcApplication1/Home/Files/foobar
Thanks in advance,
Bartek
In your web.config replace:
path="/Home/Files/*"
with:
path="Home/Files/*"
The reason for that is because when you host your application in IIS, there's a virtual directory name and the correct path is /MvcApplication1/Home/Files/* instead of /Home/Files/*. This problem is easily solved by using a relative urls in your path attribute.

ASP.NET MVC Url Route supporting (dot)

I hope that you can help me with the below problem.
I am using ASP.NET MVC 3 on IIS7 and would like my application to support username's with dots.
Example: http://localhost/john.lee
This is how my Global.asax looks like: (http://localhost/{username})
routes.MapRoute(
"UserList",
"{username}",
new { controller = "Home", action = "ListAll" }
);
The applications works when I access other pages such as http://localhost/john.lee/details etc.
But the main user page doesn't work, I would like the app to work like Facebook where http://www.facebook.com/john.lee is supported.
I used below code and it didn't work for me at all:
<httpRuntime relaxedUrlToFileSystemMapping="true" />
I was able to use below code and get the app to accept dots but I definitely wouldn't like to use below code for many different reason, please tell me there is a way to overcome this problem.
<modules runAllManagedModulesForAllRequests="false" />
Add a UrlRoutingHandler to the web.config. This requires your url to be a bit more specific however (f.e. /Users/john.lee).
This forces every url starting with /Users to be treated as a MVC url:
<system.webServer>
<handlers>
<add name="UrlRoutingHandler"
type="System.Web.Routing.UrlRoutingHandler,
System.Web, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
path="/Users/*"
verb="GET"/>
</handlers>
</system.webServer>
Just add this section to Web.config, and all requests to the route/{*pathInfo} will be handled by the specified handler, even when there are dots in pathInfo. (taken from ServiceStack MVC Host Web.config example and this answer https://stackoverflow.com/a/12151501/801189)
This should work for both IIS 6 & 7. You could assign specific handlers to different paths after the 'route' by modifying path="*" in 'add' elements
<location path="route">
<system.web>
<httpHandlers>
<add path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ApiURIs-ISAPI-Integrated-4.0" path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</location>
I was facing the same issue. So the best solution for me is:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
<system.webServer>
For anyone getting an 'Cannot create abstract class' exception when using the UrlRoutingHandler approach, it's likely due to:
Using a restricted 'path' (e.g. path="/Files/*") in your web.config declaration, and
A folder/path with the same name exists in your project
I don't think the dot is the problem here. AFAIK the only char that should not be in the user name is a /
Without seeing the route that matches john.lee/details it's hard to say what's wrong, but I'm guessing that you have another route that matches the url, preventing the user details route from being matched correctly.
I recommend using a tool like Glimpse to figure out what route is being matched.

Resources