Merge pull request #1436 from esdrubal/readerwriterlockslim
[mono.git] / mcs / class / System.Web.Mvc3 / Mvc / ValidateAntiForgeryTokenAttribute.cs
1 namespace System.Web.Mvc {
2     using System;
3     using System.Diagnostics;
4     using System.Web;
5     using System.Web.Helpers;
6
7     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
8     public sealed class ValidateAntiForgeryTokenAttribute : FilterAttribute, IAuthorizationFilter {
9
10         private string _salt;
11
12         public string Salt {
13             get {
14                 return _salt ?? String.Empty;
15             }
16             set {
17                 _salt = value;
18             }
19         }
20
21         internal Action ValidateAction {
22             get;
23             private set;
24         }
25
26         public ValidateAntiForgeryTokenAttribute()
27             : this(AntiForgery.Validate) {
28         }
29
30         //Modified to compile MVC3 with the newer System.Web.WebPages helpers
31         internal ValidateAntiForgeryTokenAttribute(Action validateAction) {
32             Debug.Assert(validateAction != null);
33             ValidateAction = validateAction;
34         }
35
36         public void OnAuthorization(AuthorizationContext filterContext) {
37             if (filterContext == null) {
38                 throw new ArgumentNullException("filterContext");
39             }
40
41             //Modified to compile MVC3 with the newer System.Web.WebPages helpers
42             ValidateAction();
43         }
44     }
45 }