3

我已经使用 servicestack razor 构建了一个应用程序。我使用一些 cshtml 视图自托管应用程序。

我有一个模板,我想在其中使用@Html.AntiForgeryToken();呈现 AntiForgery 令牌。

它在下面给了我一个错误:

Response Status

Error Code
        ArgumentException
Message
                An HttpContext is required to perform this operation. Check that this operation is being performed during a web request.

Stack Trace

 at ServiceStack.Html.AntiXsrf.AntiForgery.GetHtml()
 at ServiceStack.Html.HtmlHelper.AntiForgeryToken() at ASP.__Login.Execute()
 at ServiceStack.Razor.ViewPage.WriteTo(StreamWriter writer) 
 at ServiceStack.Razor.Managers.RazorPageResolver.ExecuteRazorPageWithLayout(IHttpRequest httpReq, IHttpResponse httpRes, Object model, IRazorView page, Func`1 layout) 
 at ServiceStack.Razor.Managers.RazorPageResolver.ResolveAndExecuteRazorPage(IHttpRequest httpReq, IHttpResponse httpRes, Object model, RazorPage razorPage) 
 at ServiceStack.Razor.Managers.RazorPageResolver.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName) 
 at ServiceStack.WebHost.Endpoints.AppHostHttpListenerBase.ProcessRequest(HttpListenerContext context) 
 at ServiceStack.WebHost.Endpoints.Support.HttpListenerBase.ListenerCallback(IAsyncResult asyncResult)

有没有办法在 servicestack razor 的自托管页面上获取 Antiforgery 令牌?

4

0 回答 0