Is it possible to use jQuery AJAX calls to authenticate forms with ASP.NET MVC? I have not found any such examples.
More specifically, how can I set up auth cookie on the page (without any redirects) so that I can consistently request a certified AJAX request?
Yes, this is possible. Simply submit the entry form using the method and if any return url returns a JSON datastructure with it.
I have created a Light Log ResultDTO class which I return as json:
Public class LoginResultDTO {public bool success {Received; Set;} public string message {get; Set;} public string return url {get; Set;}}
Here is a script block from my logon:
& lt; Script type = "text / javascript" & gt; $ {Document} .ready (function () {var form = $ ($ ("form") [0]); form.submit (function () {var data = form.serialize (); $ .post (form Entry ("Action"), data, function (result, status) {if (result; successful & amp; result; returnar url) {location.href = result.ReturnUrl;} and {warning (result message);}}, "Jsan"); return false;});}); & Lt; / Script & gt;
This AJAX wrap up the logon form. Note that this is the simplest implementation of the JavaScript code possible, but it's a place to start.
Then I have modified my logon action in the Account Administrator and put something in the relevant places like this:
if (request .asajax request) () Jason Returns (New LoginRTD DTO {Successful = Truth, Message = "Successfully Logged In"}); } And {return view (); }
So this is an ultralight, but its full version of how jquery authentication can be done in asp.net MVC.
Comments
Post a Comment