I am using Umbraco 7 for one of my websites. I am currently creating the login/logout section of the website.
Everything is working fine except after the user enters wrong credentials I need to show a new div tag. I use TempData to store the error and the error is their when I debug.
Except It won't refresh the HTML because I am using jQuery Ajax to submit the form.
Yes, this is normal behavior of your code.
I prefer to you use some @Html.AntiForgeryToken() in the form code, and verification attribute in the controller, it will be more secure.
Another thing, you have return RedirectToCurrentUmbracoPage();, this code isn't the best way to get answer from the server if you are using ajax submit. Try to use json, or http response codes.
so for every form you implement you have to define the @Html.AntiForgeryToken() and in your controller add the [ValidateAntiForgeryToken] attribute to be more secure?
Update HTML after Form submit using Ajax
Hi,
I am using Umbraco 7 for one of my websites. I am currently creating the login/logout section of the website.
Everything is working fine except after the user enters wrong credentials I need to show a new div tag. I use TempData to store the error and the error is their when I debug.
Except It won't refresh the HTML because I am using jQuery Ajax to submit the form.
jQuery code:
Controller:
View:
Is this normal behaviour of the ajax submit? Do I need to use the error() handler of the jQuery ajax to handle the error message?
/Michael
Hi Michaël,
Yes, this is normal behavior of your code. I prefer to you use some @Html.AntiForgeryToken() in the form code, and verification attribute in the controller, it will be more secure.
Another thing, you have return RedirectToCurrentUmbracoPage();, this code isn't the best way to get answer from the server if you are using ajax submit. Try to use json, or http response codes.
Thanks, Alex
Hi Alex,
thanks for your reply.
So instead of using the TempDate I should return some json object with the error or success message and then display this in the disered HTML?
/Michael
Michael,
Yes json will be better, and it will be faster, but please do not forget about security code )) I think it's important.
Thanks
Alex,
so for every form you implement you have to define the
@Html.AntiForgeryToken()
and in your controller add the[ValidateAntiForgeryToken]
attribute to be more secure?/Michael
Yes, it detect and block CSRF using the “user-specific tokens” technique. You can replace it with captcha.
/Alex
Alex,
ok its clear to me.
Thanks
/Michael
is working on a reply...