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
Related
I recently updated some ASP.NET Nuget packages and modified the index.html file of my web site. Now I get 404-Not Found error but ONLY for the root path, i.e. when the web site address is typed without subdirectory or file name.
If I explicitly append "/index.html" then the default document is displayed correctly.
I also noticed that the line below in my web.config file has an unexpected behavior: If I remove the line, then the root path can be displayed, but the Web API requests return 404-Not Found response. If I keep it, then Web API requests work but the default document causes 404-Not Found.
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
The complete "handlers" section of web.config is as follows:
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
I made no changes to the default document setting or physical path file permissions. How can I fix this?
I just discovered that the problem has nothing to do with my modification in index.html. The actual cause originated from the way MVC routing works: I had just added MVC components to my project, and newly-added MVC route config started digesting all extensionless paths. As per this explanation, I just added an exception for the root path (the empty string), and the problem was fixed:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapMvcAttributeRoutes();
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("");
...
}
}
I have been developing an application that was hosted on IIS 6 and we have just upgraded our server that uses IIS 8.5 but can't get it to work on the new server.
The application has a custom handler that's called when a file with extension .XmlDataTypes is requested.
For this to work in IIS6 I set up a mapping as:
Extension: '.XmlDataTypes'
Path: 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll'
Verbs: All.
In Web.config:
<httpHandlers>
<add verb="*" path="*.XmlAmenityData" type="XmlHandler"/>
<add verb="*" path="*.XmlDataTypes" type="XmlDataTypes"/>
</httpHandlers>
And this works fine.
In IIS8.5 I've tried adding a Managed Handler with:
Requested path: '*.XmlDataTypes'
Type:, selected 'XmlDataTypes'
Name: XmlDataTypes
This then added to the web.config file:
<system.webServer>
<handlers>
<add name="XmlAmenityData" path="*.XmlAmenityData" verb="*" type="XmlHandler" resourceType="File" preCondition="integratedMode" />
<add name="XmlDataTypes" path="*.XmlDataTypes" verb="*" type="XmlDataTypes" resourceType="File" preCondition="integratedMode" />
</handlers>
</system.webServer>
When I run a page that requests a URL with extension .XmlDataTypes via a jQuery function I just get an 404 not found error.
Thanks in advance for any help.
J.
It looks like those are files on your disk. If they are, your solution could be as simple as adding the following to your web.config under "system.webServer".
<staticContent>
<mimeMap fileExtension=".XmlAmenityData" mimeType="application/xml" />
<mimeMap fileExtension=".XmlDataTypes" mimeType="application/xml" />
</staticContent>
That's it.
However, if you are really relying on HTTP Handlers, please note that the "Type" need to be fully qualified with the assembly name at the least.
So your type need to include the namespace as well.
In your code, "XmlHandler" isn't fully qualified with the namespace and the assembly isn't mentioned. Ensure that it is.
Finally, change the "resourceType" to "Unspecified" or IIS will ensure that a file truly exist before executing your handler.
None of the answers I've found here or on similar questions on stackoverflow worked for me.
I'm using IIS 8.5, .Net v4.0, Integrated, and was still getting a 404 with the following handler config:
<system.webServer>
<handlers>
<add name="testEmail" path="*.em" verb="*" type="MyApp.testRazorEmailHandler, MyApp" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
I enabled tracing and found the following :
116. -HANDLER_CHANGED
OldHandlerName testEmail
NewHandlerName System.Web.Mvc.MvcHandler
NewHandlerModules ManagedPipelineHandler
NewHandlerScriptProcessor
NewHandlerType System.Web.Mvc.MvcHandler, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
As you can see it looks like it had correctly picked up the request using my custom HttpHandler testEmail but MVC had stolen it.
I opened my route definitions in RouteConfig.cs and found that adding:
routes.IgnoreRoute("{resource}.em");
I got it to ignore requests meant for my Handler.
Hope this helps someone - I was tearing my hair out!
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.
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.
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!