Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating AntiForgeryToken in WebForms

I have a .NET Webforms site thanks needs to post to my MVC Application which currently sits inside the Webform site as a separate application.

The Webform application need to POST some sensitive values to the MVC Application.

Is there a way to generate a AntiForgeryToken() in my WebForms Application so it can be passed with the form post.

Otherwise does anyone know of any other custom anti forgery code that will allow me to do something similar to the MVC's AntiForgeryValidation.

like image 921
Naz Avatar asked Aug 24 '09 10:08

Naz


1 Answers

Implementing it yourself is not too difficult.

  • Generate a GUID
  • Put it in a hidden field
  • Also put it in Session or Cookie (in the latter case, with some anti-tamper protection)
  • At the start of processing the form compare the field and stored token.

(If you look at the implementation of MVC, there is very little more to it. A few helper methods is all you need.)

like image 189
Richard Avatar answered Sep 17 '22 14:09

Richard