资源未找到错误

时间:2013-07-25 09:39:33

标签: c# asp.net-mvc asp.net-mvc-4

我在HomeController上访问方法时遇到问题。我告诉你方法的代码:

[HttpGet]
    public ActionResult DecriptIdentifiantEtRedirige(string login_crypter, string mdp_crypter)
    {
        string loginAcrypter = _globalManager.ProtegeMotDePasse(login_crypter);
        string MdpAcrypter = _globalManager.ProtegeMotDePasse(mdp_crypter);
        User UserApp = new Models.User(login_crypter, mdp_crypter);
        if (UserApp.AuthentificationValidee(UserApp.UserLogin, UserApp.Password))
        {
            Session["Name"] = UserApp.UserLogin;
            return RedirectToAction("Accueil", "Home");
        }
        else
        {

            return RedirectToAction("ValiderAuthentification", "Home");
        }

    }

然后在RouteConfig.cs中,我写了这样的路线:

routes.MapRoute(
        name: "AuthentificationApresDecryptage",
        url: "{controller}/{action}/{login_crypter}/{mdp_crypter}",
        defaults: new { controller = "Home", action = "DecriptIdentifiantEtRedirige", login_crypter = "", mdp_crypter = "" }
        );

但问题是当我尝试使用该链接在浏览器中访问该方法时: “http://mydomain.com/DecriptIdentifiantEtRedirige/12345/54321” 它显示一个错误:“找不到资源”。

有人有想法吗? 感谢。

1 个答案:

答案 0 :(得分:2)

试试这个,

routes.MapRoute(
        name: "AuthentificationApresDecryptage",
        url: "{controller}/{action}/{login_crypter}/{mdp_crypter}",
        defaults: new { controller = "Home", action = "DecriptIdentifiantEtRedirige", login_crypter = UrlParameter.Optional, mdp_crypter = UrlParameter.Optional }
        );