1

I am specifying a custom route and an action. What am I doing wrong? I am getting a 404 error. I set it up similar to this example: http://www.codeproject.com/Articles/190267/Controllers-and-Routers-in-ASP-NET-MVC

URL:

http://localhost:14133/ScanSummary/mywebsite.com

Route:

routes.MapRoute(
    "ScanSummary",
    "ScanSummary/{domain}",
    new { controller = "ScanSummary", action = "Get" }
    );

Controller:

public class ScanSummaryController : Controller
{
    public ActionResult Get(string domain)
    {
        return View();
    }
}
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Greg Finzer
  • 6,714
  • 21
  • 80
  • 125
  • possible duplicate of [Dots in URL causes 404 with ASP.NET mvc and IIS](http://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis) – Erik Philips Apr 14 '14 at 15:38

2 Answers2

2

Because of the .com extension, IIS thinks that this is a file on the disk and attempts to serve it directly instead of going through the pipeline.

One way to fix the issue is by running managed modules for all requests:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    ...
</system.webServer>

Another (and IMHO better way) is to explicitly map the MVC handler to this endpoint:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="false" />
    <handlers>
        ...
        <add 
            name="SvanSummaryHandler" 
            path="ScanSummary/*" 
            verb="GET,HEAD,POST" 
            type="System.Web.Handlers.TransferRequestHandler"
            preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>

Also I would recommend you reading the following blog post to better understand the gotchas that are awaiting you if you intend to be passing arbitrary characters in the path portion of an URL: http://www.hanselman.com/blog/ExperimentsInWackinessAllowingPercentsAnglebracketsAndOtherNaughtyThingsInTheASPNETIISRequestURL.aspx

And simply follow what Scott Hanselmann suggests:

After ALL this effort to get crazy stuff in the Request Path, it's worth mentioning that simply keeping the values as a part of the Query String (remember WAY back at the beginning of this post?) is easier, cleaner, more flexible, and more secure.

Oh and to make the things even funnier you may take a look at this blog post: http://bitquabit.com/post/zombie-operating-systems-and-aspnet-mvc/

After reading those did you start using query strings? I hope you did.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

you need to replace

new { controller = "ScanSummary", action = "Get" }

with

new { controller = "ScanSummary", action = "Get", domain = UrlParameter.Optional }
Antony Koch
  • 2,043
  • 1
  • 16
  • 23