我已将剃须刀视图更改为handlebars模板。
在剃刀视图中:
using (Html.BeginForm("Start", "Form", FormMethod.Post, new { formTypeId = @Model.TypeId, organizationId = @Model.OrganizationId }))
{
@Html.AntiForgeryToken()
<input type="hidden" name="formTypeId" value="@Model.TypeId" />
<input type="hidden" name="organizationId" value="@Model.OrganizationId" />
<button class="btn btn-primary btn-block" type="submit">Start</button>
}在handlebars模板中:
<form action="{{StartLink}}" method="post">
<input type="hidden" name="formTypeId" value="{{TypeId}}" />
<input type="hidden" name="organizationId" value="{{OrganizationId}}" />
<button class="btn btn-primary btn-block" style="margin-bottom: 5px;" type="submit">Start</button>
</form>我不确定如何将防伪令牌添加到handlebars窗体中。
发布于 2018-08-14 05:32:34
好的,这是我想出来的。
在我的index.cshtml中,我将一个防伪令牌传递给创建handlebars模板的js。
@section scripts {
<script>
$(function () {
window.formListBuilder = new app.components.FormListBuilder({
container: '#forms-container',
baseUrl: '@baseUrl.ToString()',
antiForgeryToken: '@Html.AntiForgeryToken()',
currentUser: JSON.parse('@Html.Raw(Json.Serialize(currentUser))')
})
});
</script>
}然后在handlebars模板中,我使用了防伪标记。
<form action="{{StartLink}}" method="post">
{{{antiForgeryToken}}}
<input type="hidden" name="formTypeId" value="{{TypeId}}" />
<input type="hidden" name="organizationId" value="{{OrganizationId}}" />
<button class="btn btn-primary btn-block" style="margin-bottom: 5px;" type="submit">Start</button>
</form>这是一个可接受的解决方案,还是以某种方式绕过了安全性?
https://stackoverflow.com/questions/51829391
复制相似问题