0

I have the routing as:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Demo", action = "Index", id = UrlParameter.Optional }
);

The routing works fine, but when I use a redirection as:

return RedirectToAction("Index", "Demo", new { data = "someData" });

The redirection works but the URL is displayed as

www.mydomain/applicationName/?data=somedata

and the form have the action as /applicationName/

The main issue is somewhere in the scripts, there are dynamic load of content where the URL is given as ../DirName/image.jpg expecting there will me controller name present, which is also in use in other flows. Here I am getting a 404, as the URL that should have been

www.mydomain/applicationName/DirName/image.jpg

is showing

www.mydomain/DirName/image.jpg

Is there any easy workaround for this?

SamGhatak
  • 1,487
  • 1
  • 16
  • 27
  • 1
    If you want `ww.mydomain/applicationName/somedata` then it needs to be `new { id = "someData" }` (and the parameter name of the method should also be named `id`) or change the route definition to `url: "{controller}/{action}/{data}",` –  Feb 23 '16 at 08:05
  • 1
    And as for the 404, its because of the `.` (dot) in the url - refer [this question/answers](http://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis) –  Feb 23 '16 at 08:07
  • Thanks @StephenMuecke, your first comment serves my purpose :) – SamGhatak Feb 23 '16 at 09:02

1 Answers1

0

Got the issue fixed as suggested by @StephenMuecke.

The correct in routing would be:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{data}",
            defaults: new { controller = "Demo", action = "Index", data= UrlParameter.Optional }
);

Now the URL is displayed as:

www.mydomain/applicationName/DirName/image.jpg

SamGhatak
  • 1,487
  • 1
  • 16
  • 27