2

In my Account/Login controller method, I have something like:

var classA = GetObject(); //actual code omitted
switch(classA.PropA)
{
    case 1:
        return RedirectToAction("Action2", "Registration");
    //more case code omitted
    default:
        return RedirectToAction("Index", "Registration");
}

All the cases work fine in the switch block except the default where it's suppose to go to Index in RegistrationController. Instead of that, it takes me to localhost:port/Registration, where the action Index is omitted.

It works fine if the ActionName is changed to something else - Index2 for example. Also works fine if the controller name is changed to something else.

RouteConfig is just the auto-generated code from creating the project, which is as follows:

    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 }
        );
     }

Thanks in advance.

10
  • What happens when RedirectToAction("Index", "Registration"); executes? Commented May 18, 2017 at 8:53
  • Sorry I did forget to mention that. It just goes to localhost:port/Registration instead Commented May 18, 2017 at 8:55
  • Did you put debugger on Index action method? Commented May 18, 2017 at 9:00
  • It's not stepping into Registration/Index at all Commented May 18, 2017 at 9:05
  • and if you enter localhost:port/Registration/index then? Commented May 18, 2017 at 9:14

3 Answers 3

4

There is nothing wrong with the route setting the reason it does not include Index in the URL because according to default route

url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

when you enter /Registration the route already knows the default action which is index so it does not add /index in URL and about

403.14 forbidden

if you look at this post HTTP Error 403.14 - Forbidden - MVC 4 with IIS Express it could be because you might have a file or folder named Registration in the project directory

Sign up to request clarification or add additional context in comments.

3 Comments

This is absolutely spot on! Thanks!
@ChenChen you can accept my answer if it helped :) if you dont know how you can check this How to accept an answer
@ChenChen no problem :)
1

If you use the RedirectionToAction("Index","ControllerName"); it will redirect you with the default mapping config to localhost:port/ControllerName and in your case if you execute the RedirectionToAction("Index","ControllerName"); it will redirect you to localhost:port/Registration

1 Comment

This clears things up a lot. Thanks. However, is "Registration" a reserved word or something? As i'm getting "HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory" with that controller, but not with any other controllers
0

Try to use on

return RedirectToAction("Index");

and in RouteConfig you can route Action "Index" to Controller "Registration"

like

routes.MapRoute("Index", "Index", new { controller = "Registration", action = "Index" });

1 Comment

You should also verify this code in RouteConfig. routes.MapRoute("Registration", "Registration/{action}/{id}", new { controller = "Registration", Action = "Index", id = UrlParameter.Optional });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.