Ich habe folgende ControllerWarum MVC gibt mir 404 nicht gefunden, wenn 2 Teilen URL als UrlParameter.Optional markiert
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");
}
}
Die 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 wie das
istpublic 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}
);
}
Aber wenn ich die Anwendung auf IIS und ich es ausführen, gibt mir 404 nicht gefunden, wenn Sie zum Stamm der sit navigieren e (Ich würde erwarten, dass es um die Strecke passen, die HomeController.Index Aktion umleitet)
ein [mcve] wäre großartig! –
Was befindet sich in der Adressleiste des Browsers? –
@ James R. http: // localhost/WebApp% 20/ –