简体   繁体   English

通过jquery ajax请求将用户重定向到“登录”页面

[英]Redirect user to Login page, from an jquery ajax request

Iam using custom Authorize filter to on my action method to check if user has an access to it. 我在我的操作方法上使用自定义“授权”过滤器来检查用户是否可以访问它。 If user does not have an access then user is redirected to Unauthorize page. 如果用户没有访问权限,则该用户将被重定向到“取消授权”页面。

The problem iam facing here is iam using Jquery Ajax request to call that action method. IAM面临的问题是IAM使用Jquery Ajax请求来调用该操作方法。 Everything works well if the user has an access. 如果用户具有访问权限,则一切正常。 But if the user does not have an access the code is not able to bind the View("Unauthorize") and it display the existing view on the browsers screen; 但是,如果用户没有访问权限,则该代码将无法绑定View(“ Unauthorize”),并且它将在浏览器屏幕上显示现有视图;

Any suggestions would be helpful. 任何的意见都将会有帮助。

Thanks. 谢谢。

The thing is that ajax requests can not send a redirect response. 问题是ajax请求无法发送重定向响应。 You can instead either return a status code that tells the calling javascript to redirect or simply change the Response.ContentType to application/javascript and use window.location = "newUri" as the response body. 您可以改为返回状态代码,该状态代码告诉调用方的javascript重定向,也可以将Response.ContentType更改为application/javascript然后使用window.location = "newUri"作为响应主体。

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

相关问题 如果会话因AJAX请求而过期,则重定向到登录页面 - Redirect to login page if session expires from AJAX request 如何从 Ajax 回发重定向到登录页面? - How to redirect to Login page from an Ajax postback? 通过 ajax/jQuery $.post 将未经身份验证的用户重定向到不同的页面 - Redirect unauthenticated user to different page via ajax/jQuery $.post 如果请求来自某个IP范围,则将用户重定向到页面 - Redirect user to page if request is from a certain IP range 如果用户闲置了一段时间,将页面重定向到登录页面 - Redirect the page to the login page if the user sits idle for some time 如何将Controller上的Ajax reqest重新定向到登录页面? 。 - How to redirect unauthorize Ajax reqest on Controller to login page? . ASP.NET MVC 重定向到 ajax 内容调用上的登录页面 - ASP.NET MVC redirect to login page on ajax content call 不要重定向到登录页面 - Don't redirect to Login page 当用户需要再次登录时,Ajax.ActionLink返回div中的“登录”页面 - Ajax.ActionLink returns Login page within div when user need to login again 用户路由到关键区域时,ASP.NET MVC身份验证重定向到登录页面 - ASP.NET MVC Authentication Redirect to Login Page when user route to the critical area
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM