doogdeb
doogdeb

Reputation: 403

MVC 2 Antiforgerytoken session issue

I've implemented the antiforgerytoken in my MVC 2 app.
I have also added a machine key in the web.config. When the session expires and I try and do a post it throws a A required anti-forgery token was not supplied or was invalid error.
It seems like the antiforgery token is expiring.

My question is

Upvotes: 2

Views: 1488

Answers (1)

LeftyX
LeftyX

Reputation: 35587

I've never experienced such problem and I am pretty sure that the AntiForgeryToken do not expire but I was reading here and it seems that someone has had your problem.

I do not use the machine key. I simply do something like this:

<% using(Html.Form("UserProfile", "SubmitUpdate")) { %>
    <%= Html.AntiForgeryToken("AF-MyApp-token") %>
    <!-- rest of form goes here -->
<% } %>

and server-side:

[ValidateAntiForgeryToken(Salt="AF-MyApp-token")]
public ViewResult SubmitUpdate()
{
    // ... etc
}

Upvotes: 3

Related Questions