/// <summary> /// IsTrapped /// </summary> /// <param name="httpContext"></param> /// <returns></returns> public bool IsTrapped(HttpContext httpContext) { if (httpContext.Items.TryGetValue(HttpContextItemName, out object value) == false) { HoneypotSettings settings = httpContext.RequestServices.GetRequiredService <HoneypotSettings>(); bool trapped = httpContext.Request.Form .Any(x => settings.IsFieldName(x.Key) && x.Value.Any(v => string.IsNullOrEmpty(v) == false)); httpContext.Items.Add(HttpContextItemName, trapped); return(trapped); } else { return((bool)value); } }
public HoneypotTagHelper(HoneypotSettings settings) { Settings = settings; }
public static IServiceCollection AddHoneypot(this IServiceCollection services, HoneypotSettings settings) { services.AddTransient <HoneypotAttribute>(); services.AddTransient <HoneypotService>(); services.AddSingleton(settings); return(services); }
public HoneypotAttribute(HoneypotSettings settings) { Settings = settings; }