简体   繁体   中英

ASP.NET and Javascript not working in Firefox issue

I have problem with javascript code inside my controller. The below code working fine with all the browser(IE,Chrome and Safari) but not in Firefox? It prints the javascript code in the browser. Please help me anyone had the same issue. Thanks in advance.

public ActionResult LogOut()
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    sb.Append("<script type = 'text/javascript'>");
    sb.Append("window.location.href = 'myurl'");
    sb.Append("</script>");

    return JavaScript(sb.ToString());
}

If any other way to do this please share with me.

Why not just use a Redirect action result to redirect the user to myurl ?

Get rid of the StringBuilder logic and just:

return RedirectToAction(yourAction);

if it's an action in the same controller, or:

return Redirect('myurl');

if it's an URL outside the controller.

Try returning Content instead of JavaScript:

return Content(sb.ToString());

But if you just need to redirect users, then it's better to use redirect:

return Redirect("myurl");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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