How do you handle ajax requests when user is not authenticated?

前端 未结 6 2096
刺人心
刺人心 2020-12-08 02:51

How do you handle ajax requests when user is not authenticated?

Someone enters the page, leaves room for an hour, returns, adds comment on the page that goes throuh

6条回答
  •  再見小時候
    2020-12-08 03:19

    I would propose creating your own AuthorizeAttribute and if the request is an Ajax request, throw an HttpException(401/403). And also switch to use jQuery's Ajax Method instead.

    Assuming you've implemented error pages and they return the correct status code, the error callback will be executed instead of the success callback. This will be happen because of the response code.

提交回复
热议问题