4
我安裝Microsoft.AspNetCore.Antiforgery我的asp.net核心.NET Framework應用程序,添加到配置服務使用防僞使用Ajax或AngularJs
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddTransient<ISession, JwtSession>(s => JwtSession.Factory());
//services.AddCors();
services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
services.AddMvc();
}
我想在一個控制器來使用它,並做了如下:
[Route("[action]"), Route("")]
[HttpGet]
public IActionResult Index()
{
var f = _antiforgery.GetAndStoreTokens(HttpContext);
return View();
}
但不知道如何把鑰匙放到視圖中。
和Don」:
過濾器的使用情況t忘記添加「使用Microsoft.Extensions.DependencyInjection」,否則通用的GetService擴展將不可用。 – Zygimantas