我正在开发MVC登录应用程序
一旦用户成功验证,我想从控制器重定向到MainPage URL(例如:-www.amazon.in)
这是我的代码
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
var result = await SignInManager.PasswordSignInAsync(model.StoreNumber, model.UserName, model.Password, model.RememberMe, shouldLockout: true);
switch (result)
{
case MolSignInStatus.Success:
return RedirectToLocal(returnUrl);
}
}
private ActionResult RedirectToLocal(string returnUrl)
{
var returnPath = new Uri(returnUrl).AbsolutePath;
if (Url.IsLocalUrl(returnPath))
{
//return Redirect(returnUrl);
return JavaScript("window.location = 'www.amazon.in'");
}
return RedirectToAction("Index", "StoreRegistration");
}
@using (Ajax.BeginForm("Login", "Account", new AjaxOptions { HttpMethod = "POST", OnSuccess = "successOfAddition", OnFailure = "failureOfAddition" }
))
{
}
<script type="text/javascript">
function successOfAddition(data) {
if (data.MessageType == '') {
}
}
function failureOfAddition(data) {
debugger;
showAlert(data.MessageType, data.Message);
}
</script>
这里我想从控制器的RedirectToLocal ActionResult方法获取returnUrl值,基本上我想在成功登录时将用户重新定向到新的网站。
以下代码不适用于Ajax Post
return Redirect(returnUrl);
所以我试图使用
return JavaScript("window.location = + 'www.amazon.in'");
它工作正常但不是硬编码url值我想让它传递给我对OnSuccess函数的看法。