How does redirect to returnUrl work in Asp.Net MVC5

前端 未结 4 678
生来不讨喜
生来不讨喜 2020-12-31 11:55

I\'ve started a new MVC 5 site, using the new Asp.Net Identity with Owin. In my \"account\" controller which has the attribute [Authorize], I have fairly standard actions;

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 12:26

    You need to check if the url is local indeed using this method (it is not handled by the framework automatically): http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.islocalurl%28v=vs.118%29.aspx

    if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
    {
      return Redirect(returnUrl);
    }
    

提交回复
热议问题