Why @Html.AntiForgeryToken() returns null?

676 Views Asked by At

I have configured my web asp.net mvc app in iis on our server. after app starts the an exception occurs such below:

Object reference not set to an instance of an object.
Line 10: {
Line 11:     <div class="form-horizontal">
Line 12:         @Html.AntiForgeryToken()  <-- here

i've checked the MachineKey (in the web.config) of the app in iis which is :

<machineKey decryptionKey="AutoGenerate,IsolateApps" validation="SHA1" validationKey="AutoGenerate,IsolateApps" />

I can't figure out what is the problem!

Update:

also, I checked the session,But it's not null. I got Session.SessionID in a razor and I got a valid value (hutqqygxwbvvwaerztvamf1n).

1

There are 1 best solutions below

0
On

I just got a similar error. A working form started to fail on the @html.AntiForgeryToken().

It turned out to be one of the lines of html I added:

<a href=# onclick="@(Html.Raw(String.Format("EditCrops({0})",@ViewBag.ContactId)))">Alternate Contacts

When I commented out this line of html, it worked again.