fixing possible NRE, when viewContext is null
This commit is contained in:
parent
f4c80ca99f
commit
bc009fc0f1
|
|
@ -644,9 +644,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
||||||
public virtual HtmlString SetAntiforgeryCookieAndHeader()
|
public virtual HtmlString SetAntiforgeryCookieAndHeader()
|
||||||
{
|
{
|
||||||
var viewContext = ViewContext;
|
var viewContext = ViewContext;
|
||||||
var antiforgery = viewContext?.HttpContext.RequestServices.GetRequiredService<IAntiforgery>();
|
if (viewContext != null)
|
||||||
antiforgery.SetCookieTokenAndHeader(viewContext?.HttpContext);
|
{
|
||||||
|
var antiforgery = viewContext.HttpContext.RequestServices.GetRequiredService<IAntiforgery>();
|
||||||
|
antiforgery.SetCookieTokenAndHeader(viewContext.HttpContext);
|
||||||
|
}
|
||||||
return HtmlString.Empty;
|
return HtmlString.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue