Skip to content

Instantly share code, notes, and snippets.

View jglozano's full-sized avatar

Javier Lozano jglozano

View GitHub Profile
@jglozano
jglozano / server.txt
Created March 30, 2024 00:35
Server URL
https://drive.google.com/uc?export=download&id=1n7Ji3ca9V9PgSud36-QNR0fU44r95YKr
public class MessageAttribute : ActionFilterAttribute {
// Tell Ninject to inject the type
[Inject]
public IMessageService MessageService {get; set;}
public override void OnActionExecuted(ActionExecutedContext filterContext) {
var actionName = filterContext.ActionDescriptor.ActionName;
filterContext.Controller.ViewModel.FilterMessage = MessageService.GetMessage(actionName);
}
}
public class InjectableFilterProvider : FilterAttributeFilterProvider {
public IKernel Kernel { get; private set; }
public InjectableFilterProvider(IKernel kernel) {
Kernel = kernel;
}
public override IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) {
var filters = base.GetFilters(controllerContext, actionDescriptor);
@jglozano
jglozano / Startup.cs
Created August 19, 2022 15:45
OWIN/Okta/SameSite Cookies
using Microsoft.Owin;
using Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using System.Configuration;
using System.Security.Claims;
using IdentityModel.Client;
@jglozano
jglozano / Startup.cs
Created August 4, 2022 22:07
OWIN Middleware for X-FORWARDED- Headers
using Microsoft.Owin;
using Owin;
using System.Threading.Tasks;
[assembly: OwinStartup(typeof(OWINSample.Startup))]
namespace OWINSample
{
public class Startup
{
@jglozano
jglozano / Program.cs
Created August 4, 2022 21:30
ASP.NET Core X-FORWARDED- Headers
using Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
// Configure the Forwarded Headers
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
@jglozano
jglozano / localtestme.txt
Created September 11, 2013 15:40
localtest.me how-to
There's a *free* domain we can all leverage called http://localtest.me . ~All~ subdomains resolve
to 127.0.0.1. You can make ~any~ subdomain you want without having to go to some admin page or
account page and 'creating' it. Just go and try: ping whateverYouWant.localtest.me and it should
resolve to 127.0.0.1 ! Awesome! For more info: http://readme.localtest.me/
2. Make sure your machine can accept this domain, etc.
a) Run command line AS ADMIN.
b) type => netsh http add urlacl url=http://create-some-subdomain-here.localtest.me:1337/ user=everyone
3. Add this binding to your website.
a) IIS: Just open up IIS -> your website -> Bindings -> add the domain name.
b) IIS Express: open up \\MyDocuments\IISExpress\config\application.config ... and look for the <sites> element (around line 155).
@jglozano
jglozano / AccessFilter.cs
Created January 21, 2022 22:24
Reading Body from HttpRequest
// snippet around reading from HttpRequest.Body
var request = context.Request;
request.EnableBuffering();
// deserialize into temp structure using System.Text.Json.JsonSeralizer
var temp = await JsonSerializer.DeserializeAsync<RequestTemp>(request.Body,
options: new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
request.Body.Seek(0, SeekOrigin.Begin);
@jglozano
jglozano / .bash_profile
Last active January 27, 2021 17:48
bash profile that adds support for Git
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
fi
@jglozano
jglozano / Invokers.cs
Created April 6, 2012 20:00
Action Invoker Registry With Expression
public class Invokers : ActionInvokerRegistry {
public Invokers() {
// Define an expression for which to search the registered list
Expression<Fun<RequestContext, ControllerInfo, bool>>> fooSelector =
(context, info) => return info.ControllerName == "Foo";
// Register the invoker -> selector for the engine to know
Use<FooInvoker>(fooSelector);