[英]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.