0

The model and controllers in my MVC application throw LoginRequired exceptions whenever a public user attempts to access a secure resource. I am listening for dispatch errors and when I detect one that is a LoginRequired exception, I then construct and return a custom response.

If the request was a normal HTTP request things are simple - I return a 302 redirect, and the 'location' is the login page. But what about when the request is AJAX?

I have read here How to manage a redirect request after a jQuery Ajax call about setting a response header then looking for it in a global ajax success handler. I can do that no problems, but surely there should be a HTTP status code to deal with this?

What would be a good choice of code? I need one that is a reasonably good fit semantically, but is not going to automatically invoke any behaviour on the user agent.

Community
  • 1
  • 1
DatsunBing
  • 8,684
  • 17
  • 87
  • 172
  • so what you mean you can pass your content in ie. json form `{'status':'login required','content':'--- (nothing cause the user id not authed) ---'}` but you said the you want some http status or http header right? but why? – Sina R. May 06 '14 at 09:27
  • I just thought there would be a http status for this kind of scenario. – DatsunBing May 06 '14 at 22:22

1 Answers1

0

You know I am not expert in such things but when I wanted to make a resume-able download I had added some headers and you can send costume request headers with ajax and Also you can send some response headers with PHP and get them with ajax (anything). But I think the headers are useful when they have some effects on both side or there is no different with a flag in header or a flag in body of ajax response.

And also some headers cause different behaviors on different browsers and also the browser will send different headers (just in especial little things) when you send a request (ajax or raw ,...)

ie. {'someFlallg':'ok','view':' --- content body --- '}

I hope that helps.

Sina R.
  • 1,781
  • 2
  • 19
  • 37