mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Added an html helper to set the antiforgery token cookie and get the value. Will be used for validated http get calls.
--HG-- branch : dev
This commit is contained in:
@@ -240,12 +240,25 @@ namespace Orchard.Mvc.Html {
|
||||
|
||||
#region AntiForgeryTokenOrchard
|
||||
|
||||
public static MvcHtmlString AntiForgeryTokenOrchard(this HtmlHelper htmlHelper)
|
||||
{
|
||||
public static MvcHtmlString AntiForgeryTokenOrchard(this HtmlHelper htmlHelper) {
|
||||
var siteSalt = htmlHelper.Resolve<ISiteService>().GetSiteSettings().SiteSalt;
|
||||
|
||||
return htmlHelper.AntiForgeryToken(siteSalt);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AntiForgeryTokenValueOrchard
|
||||
|
||||
public static string AntiForgeryTokenValueOrchard(this HtmlHelper htmlHelper) {
|
||||
//HAACK: (erikpo) Since MVC doesn't expose any of its methods for generating the antiforgery token and setting the cookie, we'll just let it do its thing and parse out what we need
|
||||
var field = htmlHelper.AntiForgeryTokenOrchard().ToHtmlString();
|
||||
var beginIndex = field.IndexOf("value=\"") + 7;
|
||||
var endIndex = field.IndexOf("\"", beginIndex);
|
||||
|
||||
return field.Substring(beginIndex, endIndex - beginIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user