public static WorkflowState CsrfInjector(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { PendingPageResponse pageResponse = wrapper.PendingResponse as PendingPageResponse; if (pageResponse != null) { // For form postbacks. pageResponse.Html = pageResponse.Html.Replace("%AntiForgeryToken%", "<input name=" + "csrf".SingleQuote() + " type='hidden' value=" + wrapper.Session["_CSRF_"].ToString().SingleQuote() + " id='__csrf__'/>"); // For AJAX calls where the CSRF is in the RequestVerificationToken header: pageResponse.Html = pageResponse.Html.Replace("%CsrfValue%", wrapper.Session["_CSRF_"].ToString().SingleQuote()); } return(WorkflowState.Continue); }
/// <summary> /// Apply the Razor view engine to a page response. /// </summary> public static WorkflowState ViewEngine(WorkflowContinuation <ContextWrapper> workflowContinuation, ContextWrapper wrapper) { PendingPageResponse pageResponse = wrapper.PendingResponse as PendingPageResponse; // Only send page responses to the templating engine. if (pageResponse != null) { string html = pageResponse.Html; string templateKey = html.GetHashCode().ToString(); // pageResponse.Html = Engine.Razor.RunCompile(html, templateKey, null, new { /* your dynamic model */ }); try { pageResponse.Html = Engine.Razor.RunCompile(html, templateKey, null, new { People = codeProject2015Mvp }); } catch (Exception ex) { // Helps with debugging runtime compilation errors! Console.WriteLine(ex.Message); } } return(WorkflowState.Continue); }