How to validate the ajax post request is coming from

340 Views Asked by At

I am developing an web application in MVC4. I my application all the function is did by the ajax post call. I do not even post single form(Even not have the form tag also) all the things are did by the ajax call. but I am scared for the miss use of the my java script. Any one who got this code he can post the dummy data to my application. So I need to validate the weather the post request is coming form my website or not.

I thought that the ajax call is good instead of posting all the form to server.

Also I have did the validation at client side only. Is that also the threat for me?

And How i do the use of AntiXSSLibrary and HtmlSanitizationLibrary or AntiForgeryToken??

1

There are 1 best solutions below

2
On

Use the following code in your method

string referer = Request.ServerVariables["HTTP_REFERER"];
            if (string.IsNullOrEmpty(referer))
            {
                Response.Redirect("/UnauthorizedAccess.aspx");
            }