Asp.net mvc ASP.NET MVC-重定向();没有正确重定向

Asp.net mvc ASP.NET MVC-重定向();没有正确重定向,asp.net-mvc,Asp.net Mvc,我有这样的想法: public class AccountController : Controller { public ActionResult Login() { return Redirect("http://localhost/"); } } 我希望它将用户重定向到该页面,但它一直将其重定向到 http://localhost/Account/http://localhost/ 我在这里做错了什么?重定向到应用程序根目录: Redirect("~/")

我有这样的想法:

public class AccountController : Controller
{
   public ActionResult Login()
   {
      return Redirect("http://localhost/");
   }
}
我希望它将用户重定向到该页面,但它一直将其重定向到

http://localhost/Account/http://localhost/

我在这里做错了什么?

重定向到应用程序根目录:

Redirect("~/");

我假设您正试图在给定代码的情况下将其重定向到主页。在这种情况下,您可能只需要使用RedirectToAction,如下所示:

return RedirectToAction("Index", "Home");

好的,我解决了我的问题。实际上,我正在将编码的url传递到重定向()中;方法。这种方法似乎只适用于未编码版本的链接。

不。实际上我简化了这一点。实际上,action Login()获取returnUrl,然后对其进行编码,然后重定向它。所以这并不是那么简单。:-)那么,你可能想在你的问题中加入类似的内容。