Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ASP.NET ValidateAntiForgeryToken feature #2206

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions dev/jquery.jtable.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//Options
actions: {},
fields: {},
security: { antiforgerytoken: null},
animationsEnabled: true,
defaultDateFormat: 'yy-mm-dd',
defaultChangeMonth: false,
Expand Down Expand Up @@ -113,7 +114,8 @@
this._normalizeFieldsOptions();
this._initializeFields();
this._createFieldAndColumnList();

this._addAntiforgeryToken();

//Creating DOM elements
this._createMainContainer();
this._createTableTitle();
Expand All @@ -123,9 +125,17 @@
this._createErrorDialogDiv();
this._addNoDataRow();

this._cookieKeyPrefix = this._generateCookieKeyPrefix();
this._cookieKeyPrefix = this._generateCookieKeyPrefix();
},
/* Adds antiforgery token for MVC razor pages. to prevent cross-site request forgery by adding token to ajax call header
*************************************************************************/
_addAntiforgeryToken: function () {
var self = this;
if (self.options.security.antiforgerytoken !== null ) {
var headerobj = JSON.parse('{ "RequestVerificationToken":"' + self.options.security.antiforgerytoken + '" }');
self.options.ajaxSettings.headers = headerobj;
}
},

/* Normalizes some options for all fields (sets default values).
*************************************************************************/
_normalizeFieldsOptions: function () {
Expand Down