1

Possible Duplicate:
runtime loading of ValidateAntiForgeryToken Salt value

I have added the salt into config file but its throwing the following error. is there any way to use the Salf value from config file? I have tried to use Static instead of const but not working.

Error constant initializer must be compile-time constant

Code

public const string SaltValue= ConfigurationManager.AppSettings["SaltValue"]; 

[HttpPost]
[ValidateAntiForgeryToken(Salt = SaltValue)]
public ActionResult Index(SomeViewModel someViewModel)
{
    return View(); 
}

Many Thanks

Community
  • 1
  • 1
Scorpion
  • 4,495
  • 7
  • 39
  • 60

1 Answers1

0

You should be able to use a public static readonly SaltValue and then assign the value from ConfigurationManager.AppSettings["SaltValue"] in the constructor for the controller. It's two steps, one to create the string and one to populate the value in the constructor. Then you should be able to use it in your ValidateAntiForgeryToken attribute.

imjohnking
  • 335
  • 1
  • 6