Skip to content

Instantly share code, notes, and snippets.

@3nth
3nth / AddCsrfTokenHeader
Created September 21, 2014 19:45
Add AntiForgeryToken to Response Header
public class AddCsrfTokenHeader:ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
HttpCookie cookie = null;
// First, try and get cookie from Response. That'll be a new cookie
if (filterContext.HttpContext.Response.Cookies.AllKeys.Contains(AntiForgeryConfig.CookieName))
{
cookie = filterContext.HttpContext.Response.Cookies.Get(AntiForgeryConfig.CookieName);
@3nth
3nth / AutofacConfig
Last active March 4, 2020 19:09
AutofacConfig for ASP.NET Identity
public class AutofacConfig
{
public static void Configure()
{
var builder = new ContainerBuilder();
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<PortalUser>>().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerLifetimeScope();