Last active
December 22, 2015 17:39
-
-
Save jayhjkwon/6507780 to your computer and use it in GitHub Desktop.
jitsu deploy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ValidateRequestHeader(HttpRequestMessage request) | |
{ | |
string cookieToken = ""; | |
string formToken = ""; | |
IEnumerable<string> tokenHeaders; | |
if (request.Headers.TryGetValues("RequestVerificationToken", out tokenHeaders)) | |
{ | |
string[] tokens = tokenHeaders.First().Split(':'); | |
if (tokens.Length == 2) | |
{ | |
cookieToken = tokens[0].Trim(); | |
formToken = tokens[1].Trim(); | |
} | |
} | |
AntiForgery.Validate(cookieToken, formToken); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using (Html.BeginForm("Manage", "Account")) { | |
@Html.AntiForgeryToken() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="/Home/Test" method="post"> | |
<input name="__RequestVerificationToken" type="hidden" | |
value="6fGBtLZmVBZ59oUad1Fr33BuPxANKY9q3Srr5y[...]" /> | |
<input type="submit" value="Submit" /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
@functions{ | |
public string TokenHeaderValue() | |
{ | |
string cookieToken, formToken; | |
AntiForgery.GetTokens(null, out cookieToken, out formToken); | |
return cookieToken + ":" + formToken; | |
} | |
} | |
$.ajax("api/values", { | |
type: "post", | |
contentType: "application/json", | |
data: { }, // JSON data goes here | |
dataType: "json", | |
headers: { | |
'RequestVerificationToken': '@TokenHeaderValue()' | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test