コード例 #1
0
        public static MvcHtmlString AntiForgeryTokenSpTech(this HtmlHelper htmlHelper)
        {
            try
            {
                return htmlHelper.AntiForgeryToken();
            }
            catch (HttpAntiForgeryException)
            {
                // Remove the token so that MVC will create a new one.
                var antiForgeryTokenName = htmlHelper.GetAntiForgeryTokenName();
                htmlHelper.ViewContext.HttpContext.Request.Cookies.Remove(antiForgeryTokenName);

                // Try again
                return htmlHelper.AntiForgeryToken();
            }
        }
コード例 #2
0
ファイル: HtmlHelper.cs プロジェクト: henrikrossen/SimpleBlog
 /// <summary>
 /// Returns a form with a delete button, plus a hidden anchor we can display via Ajax to make a delete link that does a post.
 /// </summary>
 public static HtmlString FormPostLink(this HtmlHelper helper, string linkText, string actionName, string controllerName, object routeValues)
 {
     var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
     string url = urlHelper.Action(actionName, controllerName, routeValues);
     string format = @"<form method=""post"" action=""{0}"" class=""formPostLink""><input type=""submit"" value=""{1}"" />{2}</form>";
     string form = string.Format(format, helper.AttributeEncode(url), helper.AttributeEncode(linkText), helper.AntiForgeryToken());
     return new HtmlString(form + helper.ActionLink(linkText, actionName, controllerName, routeValues, new { @class = "formPostLink" }).ToString());
 }
コード例 #3
0
 public static void GetActionForm(this HtmlHelper Html, string partialViewPath, Game game, GameActionState state, string location, object model = null)
 {
     string partialView;
     if (model != null)
         partialView = Html.Partial(partialViewPath,model).ToString();
     else
         partialView = Html.Partial(partialViewPath).ToString();
     using (Html.BeginForm("TakeGameAction", "Game", new { id = game.Id, gameAction = state, actionLocation = location }, FormMethod.Post, new { role = "form" }))
     {
         string inner = Html.AntiForgeryToken().ToString() + InsertSubmitElement(partialView);
         Html.ViewContext.Writer.Write(inner);
     }
 }
コード例 #4
0
        public static MvcHtmlString FlushedAntiForgeryToken(this HtmlHelper html)
        {
            var token = html.ViewContext.HttpContext.Items[ControllerBaseExtension.FlushedAntiForgeryTokenKey] as string;

            if (string.IsNullOrEmpty(token))
            {
                // Fall back to the standard AntiForgeryToken if no FlushedAntiForgeryToken exists.
                return html.AntiForgeryToken();
            }

            var tag = new TagBuilder("input");
            tag.Attributes["type"] = "hidden";
            tag.Attributes["name"] = "__RequestVerificationToken";
            tag.Attributes["value"] = token;

            return new MvcHtmlString(tag.ToString());
        }
コード例 #5
0
        public static MvcForm BeginSecureForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes)
        {
            TagBuilder tagBuilder = new TagBuilder("form");

            Dictionary<string, object> htmlAttributesDictionary = new Dictionary<string, object>();

            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(htmlAttributes))
                htmlAttributesDictionary.Add(property.Name, property.GetValue(htmlAttributes));

            tagBuilder.MergeAttributes(htmlAttributesDictionary);
            tagBuilder.MergeAttribute("action", UrlHelper.GenerateUrl(null, actionName, controllerName, new RouteValueDictionary(), htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, true));
            tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);
            htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
            htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
            var theForm = new MvcForm(htmlHelper.ViewContext);

            return theForm;
        }
コード例 #6
0
        public static string ConfirmableActionLink(this HtmlHelper helper, string label, string message, string action, object routeValues, string controller, FormMethod formMethod)
        {
            var uniqueId = Guid.NewGuid().ToString().Replace("-", "");

            var scriptTag = new TagBuilder("script");
            scriptTag.Attributes.Add("type", "text/javascript");
            scriptTag.InnerHtml = "$(function(){ $('#" + uniqueId + "').confirmableActionLink('" + message.Replace("'", "\'") + "'); });";

            var submitButton = new TagBuilder("input");
            submitButton.AddCssClass("confirmableActionLink");
            submitButton.Attributes.Add("id", uniqueId);
            submitButton.Attributes.Add("type", "submit");
            submitButton.Attributes.Add("value", label);

            helper.ViewContext.Writer.Write(scriptTag.ToString());
            using (helper.BeginForm(action, controller, routeValues, formMethod))
            {
                helper.ViewContext.Writer.Write(helper.AntiForgeryToken());
                helper.ViewContext.Writer.Write(submitButton.ToString());
            }
            return "";
        }
コード例 #7
0
ファイル: HtmlHelper.AjaxForm.cs プロジェクト: hbulzy/SYS
 /// <summary>
 /// 输出AjaxForm表单
 /// </summary> 
 /// <param name="htmlHelper">被扩展的htmlHelper实例</param>
 /// <param name="formAction"></param>
 /// <param name="method">表单请求方式</param>
 /// <param name="options">异步提交表单选项</param>
 /// <param name="htmlAttributes">表单html属性集合</param>
 /// <returns>MvcForm</returns>
 private static MvcForm FormHelper(this HtmlHelper htmlHelper, string formAction, FormMethod method, AjaxFormOptions options, IDictionary<string, object> htmlAttributes)
 {
     TagBuilder builder = new TagBuilder("form");
     builder.MergeAttributes(htmlAttributes);
     if (!string.IsNullOrEmpty(formAction))
         builder.MergeAttribute("action", formAction);
     builder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);
     builder.MergeAttributes(options.ToHtmlAttributes());
     htmlHelper.ViewContext.Writer.Write(builder.ToString(TagRenderMode.StartTag) + htmlHelper.AntiForgeryToken());
     MvcForm theForm = new MvcForm(htmlHelper.ViewContext);
     return theForm;
 }
コード例 #8
0
 public static string AntiForgeryTokenString(this HtmlHelper htmlHelper)
 {
     var inputToken = htmlHelper.AntiForgeryToken();
     return Regex.Match(inputToken.ToString(), @"value=""(.[^""]+)""").Groups[1].Value;
 }
コード例 #9
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper)
 {
     var mvcForm = htmlHelper.BeginForm();
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
コード例 #10
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, string routeName, RouteValueDictionary routeValues, FormMethod method, IDictionary<string, object> htmlAttributes)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeName, routeValues, method, htmlAttributes);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
コード例 #11
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, string routeName, object routeValues, FormMethod method)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeName, routeValues, method);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
コード例 #12
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, string routeName)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeName);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
コード例 #13
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeValues);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
コード例 #14
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttributes)
 {
     var mvcForm = htmlHelper.BeginForm(actionName, controllerName, routeValues, method, htmlAttributes);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
コード例 #15
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues)
 {
     var mvcForm = htmlHelper.BeginForm(actionName, controllerName, routeValues);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
コード例 #16
0
ファイル: ExMvcForm.cs プロジェクト: hardCTE/EasyFrameWork
 public static MvcForm BeginTokenForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method)
 {
     var mvcForm = htmlHelper.BeginForm(actionName, controllerName, method);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }