0

I have a custom attribute which checks is user i Authenticated and if it is not in such case special json string will be returned. So i need to check for that string in data which will returned from controller after jQGrid request. How can i do that in jQGrid?

So as i understand i need to get actual response data and check is it contains only my string. Another words i need to get server response data, but i not sure how and on which event i may do that and is it possible at all.

Otherwise if it is not possible i need to call the controller before jJGrid do that to check for that value.

Reporter
  • 3,897
  • 5
  • 33
  • 47
Joper
  • 8,019
  • 21
  • 53
  • 80

1 Answers1

0

You can place additional information (like the information whether the user is authenticated) in the userdata part of the JSON response. Inside of loadComplete event handler you can use userData jqGrid parameter. See the answer and probably this one.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • is it would secure? So really i think i could just pass that value in such case an everything else just blank or something like that. – Joper Aug 10 '11 at 07:24
  • @Joper: I am not sure that I understand you correct. On the server side you know whether the user is authenticated or not and can produce the data (the whole HTML page if needed or the JSON for the grid) depend on the user authenticated state or depend on it's roles. I understood your question that you want **additionally** send the Authenticated State to the user together with JSON data for the grid. So that the user will not only see reduced or no grid contain, but the user can see the reason of this. – Oleg Aug 10 '11 at 08:34
  • I meant that in case if user is not authenticated i will return an empty result only `userdata` will contain message that user is not authenticated. It is a bit ugly(i cant keep consistence in such case) because i can't use my custom `JasonAuthonticateAttribute` in such case, but anyway looks like it is the better i can do in case of secure jQGrid action. – Joper Aug 10 '11 at 12:45
  • @Joper: I am not understand how you implemented `JasonAuthonticateAttribute` and how you plan to use it. In case of you want allow only authenticated user to fill the table you can return for example `HttpStatusCode.Unauthorized` HTTP code in the response. Then the server response can has body in absolute another form. You can use `loadError` to display the error message to the user. See [the answer](http://stackoverflow.com/questions/5500805/asp-net-mvc-2-0-implementation-of-searching-in-jqgrid/5501644#5501644) for an example. – Oleg Aug 10 '11 at 13:31
  • The logic is simple there: If user not authenticated or not in required role the action filter would return this filterContext.Result = new JsonResult() { Data ="Authorize" }; so on client i need to check for that string, and if string "Authorize" is in response i am redirecting the client to LoginPage. Unfortunately i cannot use this attribute with jQGrid action so i will reuse some of its logic to populate `userdata` with this `"Authorize"` string and on client i will do the same. – Joper Aug 10 '11 at 15:53
  • @Joper: Sorry, you can return any JSON data from the action in case of authenticated user. It is important that you set `HttpStatusCode.Unauthorized` in the HTTP header. Then you will be in the `loadError` handler and can analyse the data. If you see that request was Unauthorized you can redirect to the LoginPage from the client side. To do this you can just set `window.location` to the URL of your login page. – Oleg Aug 10 '11 at 17:13