C# Asp.NET MVC4重定向(url)引发参数异常

C# Asp.NET MVC4重定向(url)引发参数异常,c#,asp.net-mvc,asp.net-mvc-4,C#,Asp.net Mvc,Asp.net Mvc 4,这似乎是不可能的,我确信我遗漏了一些非常简单的东西,但我就是看不到 在一个action方法中,我有以下代码 var redirectUrl = FormsAuthentication.GetRedirectUrl(model.UserName, false); if (redirectUrl.IsBlank()) { return RedirectToRoute(Routes.HomeUrl); } else { return R

这似乎是不可能的,我确信我遗漏了一些非常简单的东西,但我就是看不到

在一个action方法中,我有以下代码

   var redirectUrl = FormsAuthentication.GetRedirectUrl(model.UserName, false);

   if (redirectUrl.IsBlank())
   {
       return RedirectToRoute(Routes.HomeUrl);
   }
   else
   {
       return Redirect(redirectUrl);
   }
并且实现了IsBlank()

  public static bool IsBlank(this string s)
  {
      return String.IsNullOrWhiteSpace(s);
  }
无论如何

POST /login?ReturnUrl=
UserName=xxxx&Password=xxxx
设法产生此错误

ArgumentException: Value cannot be null or empty.
Parameter name: url]
   System.Web.Mvc.Controller.Redirect(String url) +113
   WebHost.Controllers.SecurityController.Login(LoginModel model) +200
   lambda_method(Closure , ControllerBase , Object[] ) +104
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +182
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +58
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +225
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +99
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629296
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
ArgumentException:值不能为null或空。
参数名称:url]
System.Web.Mvc.Controller.Redirect(字符串url)+113
WebHost.Controllers.SecurityController.Login(LoginModel模型)+200
lambda_方法(闭包、控制器基、对象[])+104
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,对象[]参数)+14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext ControllerContext,IDictionary`2参数)+182
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary`2参数)+27
System.Web.Mvc.Async.c__显示类42.b__41()+28
System.Web.Mvc.Async.c_uuuudisplayClass8`1.b_uuuu7(IAsyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+32
System.Web.Mvc.Async.c__显示类39.b__33()+58
System.Web.Mvc.Async.c__显示类4f.b_49()+225
System.Web.Mvc.Async.c__显示类37.b__36(IAsyncResult asyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+34
System.Web.Mvc.Async.c__DisplayClass2a.b__20()+24
System.Web.Mvc.Async.c__显示类25.b__22(IAsyncResult asyncResult)+99
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+50
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+27
System.Web.Mvc.c__;u displayClassId.b__u18(IAsyncResult asyncResult)+14
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+55
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+39
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+55
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)+10
System.Web.Mvc.c__;u DisplayClass8.b__;u 3(IAsyncResult asyncResult)+25
System.Web.Mvc.Async.c__显示类4.b__3(IAsyncResult ar)+23
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+55
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+31
System.Web.Mvc.MvcHandler.System.Web.IHTTPassynchandler.EndProcessRequest(IAsyncResult结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+96296
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+155

我认为一个操作需要重定向到一个操作,而不是一个简单的URL

试着这样做:

Response.Redirect(Url.RouteUrl(new{ controller="controller", action="action"}));
试试这个:

var redirectUrl = FormsAuthentication.GetRedirectUrl(model.UserName, false);

if ( Url.IsLocalUrl(redirectUrl) )   
{
    return Redirect(redirectUrl);
}
else
{
    return RedirectToRoute(Routes.HomeUrl);
}

不正确,
返回重定向(url)
完全有效。是否为Home。调试时正在设置url?是,公共常量字符串HomeUrl=“Home”;我可以通过添加日志语句来跟踪返回url的值来解决这个问题,我只能猜测某些东西正在被优化:/