简体   繁体   English

在Async and Await方法中使用重定向

[英]Use of Redirect in Async and Await Method

I am facing a problem, I am not able to redirect to some another page by using the await call. 我遇到问题,无法使用await调用重定向到其他页面。

I have been searching for two days but i am not getting the solution. 我已经搜索了两天,但没有得到解决方案。 Following is my code: 以下是我的代码:

 public async Task<ActionResult> Login(string returnUrl)
 {
      try
      {
          if (Url.IsLocalUrl(returnUrl))
          {
               Response.Redirect(returnUrl, false);
          }
      }
 }

Calling Method: 调用方法:

public async Task<ActionResult> GotoLogin()
{
    if (ModelState.IsValid)
    {
        await Login("/myhome");
    }
}

Do you need to direct the user to the "myHome" controller? 您是否需要将用户定向到“ myHome”控制器? try RedirectToAction, 尝试RedirectToAction,

return RedirectToAction("myHome", "Home", new { area = "Home"});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM