Skip to content

Instantly share code, notes, and snippets.

View EdCharbeneau's full-sized avatar
🏠
Working from home

Ed Charbeneau EdCharbeneau

🏠
Working from home
View GitHub Profile
@EdCharbeneau
EdCharbeneau / How to use Razor Components with Auth.md
Last active August 13, 2021 14:05
Blazor powered auth pages

A tip sent to me by Brian Douglass...

The way it works is:

  • Create a new Server project with Identity activated, but no scaffolding
  • Modify Startup.cs to add the AF token as a header
  • Create a custom SignIn.razor
    • Collects credentials in a form
    • OnValidSubmit() after checking validity of credentials
      • Make Http call to Login.OnGet() and get the form, with the AF token attached
  • Build new request with Credentials + AF token in the Form data + AF token in the header.
@EdCharbeneau
EdCharbeneau / index.razor
Created February 25, 2021 15:13
Custom Events in Telerik Form component
@page "/"
@using System.ComponentModel.DataAnnotations
@inject NavigationManager NavigationManager
<div class="demo-section auto">
@if (ValidSubmit)
{
<div class="demo-alert demo-alert-success" role="alert">
The form was submitted successfully.
</div>
@EdCharbeneau
EdCharbeneau / string.isNullOrWhiteSpace.js
Created March 14, 2014 17:11
Javascript test a string to see if it is Null or Whitespace. Equivelent to C# String.IsNullOrWhiteSpace
function isNullOrWhiteSpace(str) {
return (!str || str.length === 0 || /^\s*$/.test(str))
}
// --------------------------------------------------------------------------------------
// A More Modern Scale for Web Typography
// Based on this article: http://typecast.com/blog/a-more-modern-scale-for-web-typography
// --------------------------------------------------------------------------------------
$body-font-size: 1em !default;
// Adjusts body typography to be default
// for each browser.
@mixin reset-body-font-size($size: 100%, $size-adjustment: 0.5) {
@EdCharbeneau
EdCharbeneau / AlertBox.razor
Last active August 17, 2020 17:26
EventCallbacks
<div class="alert alert-danger">
@ChildContent
</div>
@code {
[Parameter] public RenderFragment ChildContent { get; set; }
}
@EdCharbeneau
EdCharbeneau / BearerScheme.cs
Created June 4, 2020 17:08
Swagger Authorization
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description =
"JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
});
@EdCharbeneau
EdCharbeneau / ExampleMetadata.cs
Last active May 3, 2020 14:28
Create a menu from Application components.
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
public static class ExampleMetadata
{
public static IEnumerable<MenuItem> GetItems()
@EdCharbeneau
EdCharbeneau / foo.ts
Last active April 17, 2020 22:04
TypeWtf
export MyClass {
private foo: string = "hello";
public addHandler() {
window.addEventListener("resize", this.logResize);
}
public logResize() {
console.log(this); // Expected: MyClass | Actual: Window
ABOUT ED:
Ed is a Microsoft MVP and an international speaker, writer, online influencer, a Developer Advocate for Progress - [Telerik UI for Blazor](https://www.telerik.com/blazor-ui), and expert on all things web development. Ed enjoys geeking out to cool new tech, brainstorming about future technology, and admiring great design.
@EdCharbeneau
EdCharbeneau / Index.razor.cs
Last active January 27, 2020 22:58
Cancelable Event
void HandleTabChange(TabEventArgs args)
{
var value = (Foo)args.Value;
if (value.Id == 1)
{
args.Cancel = true;
}
else
{
SelectedItem = value;