0

I have the following controller

public class AccountController : Controller
    {
        [HttpPost]
        public ActionResult Login(string email, string password)
        {
            if (!ModelState.IsValid) return View();
            if (Membership.ValidateUser(email, password))
            {
                FormsAuthentication.SetAuthCookie(email, false);
                return RedirectToAction("Index", "Home");
            }
            ModelState.AddModelError("", "Wrong username or password");
            return View();
        }

        [HttpGet]
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Login", "Account");
        }
}

The HomeController

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            if (Request.Path.EndsWith("/"))
            {
                return View();
            }
            if (Request.Url != null)
            {
                return RedirectPermanent(Request.Url + " /");
            }
            return View();

        }
    }

Routing is like that

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

But when i put the application on IIS and i run it gives me 404 not found when navigating to root of the site (I'd expect it to match the route that redirects to HomeController.Index Action)

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
joesid
  • 671
  • 1
  • 10
  • 21

1 Answers1

0

It's the space (%20) that you are appending to the URL. On the line:

return RedirectPermanent(Request.Url + " /");

You could remove that space, but then you'll probably get a recursive redirect. It's not quite clear to me what you are attempting to accomplish.

James R.
  • 822
  • 8
  • 17