Skip to content

Instantly share code, notes, and snippets.

View mahizsas's full-sized avatar

MAHIZ mahizsas

View GitHub Profile
private static readonly Dictionary<string, string> Provinces = new Dictionary<string, string>(){
{"AG","Agrigento"},
{"AL","Alessandria"},
{"AN","Ancona"},
{"AO","Aosta"},
{"AR","Arezzo"},
{"AP","Ascoli Piceno"},
{"AT","Asti"},
{"AV","Avellino"},
{"BA","Bari"},
//This solution is based on the code of this tutorial https://github.com/louislewis2/AngularJSAuthentication
using Microsoft.AspNet.SignalR;
namespace Solution.Web.Providers
{
public class QueryStringIdProvider : IUserIdProvider
{
public string GetUserId(IRequest request)
{
var token = request.QueryString.Get("access_token");
var authenticationTicket = Startup.OAuthOptions.AccessTokenFormat.Unprotect(token);
@mahizsas
mahizsas / async-mediator-pipeline.cs
Last active December 29, 2016 21:18
Autofac implementation for mediator pipeline
public class AsyncMediatorPipeline<TRequest, TResponse> : IAsyncRequestHandler<TRequest, TResponse> where TRequest : IAsyncRequest<TResponse>
{
private readonly IAsyncRequestHandler<TRequest, TResponse> inner;
private readonly IAsyncPreRequestHandler<TRequest>[] preRequestHandlers;
private readonly IAsyncPostRequestHandler<TRequest, TResponse>[] postRequestHandlers;
public AsyncMediatorPipeline(IAsyncRequestHandler<TRequest, TResponse> inner, IAsyncPreRequestHandler<TRequest>[] preRequestHandlers, IAsyncPostRequestHandler<TRequest, TResponse>[] postRequestHandlers)
{
this.inner = inner;
@mahizsas
mahizsas / static-logger.cs
Last active August 29, 2015 14:14 — forked from MichaelPaulukonis/StaticLogger.cs
Static Logger with Log4net
using System.Runtime.CompilerServices;
using System.Diagnostics;
using log4net;
// TODO: you must move the below configuration call.
// It must be executed prior to any calls to Logger
// Application_Start or summat
log4net.Config.XmlConfigurator.Configure();
public class CustomError
@mahizsas
mahizsas / stopwatch-attribute.cs
Last active April 10, 2025 08:15 — forked from dasch/StopwatchAttribute.cs
ASP.NET MVC Stopwatch actionfilterattribute
using System;
using System.Web;
using System.Web.Mvc;
using System.Diagnostics;
/// <summary>
/// A simple attribute that times controller actions, returning the measured time
/// in the HTTP header "X-Duration".
/// </summary>
@mahizsas
mahizsas / proxy-handler
Last active August 29, 2015 14:13 — forked from anth-3/passThruProxy.cs
Sample proxy for http request
<%@ WebHandler Language="C#" Class="PassThruProxy" Debug="true" %>
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Web;
public class PassThruProxy : IHttpHandler {
public PassThruProxy( ) { }
@mahizsas
mahizsas / EF-FluentApi
Last active July 22, 2019 08:50 — forked from aadamsx/EF-FluentApi
Description how to work EF Fluent Api
Introduction
The code first fluent API is most commonly accessed by overriding the OnModelCreating method on your derived DbContext. The following samples are designed to show how to do various tasks with the fluent api and allow you to copy the code out and customize it to suit your model, if you wish to see the model that they can be used with as-is then it is provided at the end of this article.
Property Mapping
The Property method is used to configure attributes for each property belonging to an entity or complex type. The Property method is used to obtain a configuration object for a given property. The options on the configuration object are specific to the type being configured; IsUnicode is available only on string properties for example.
@mahizsas
mahizsas / proxy-httphandler.cs
Last active August 29, 2015 14:13 — forked from kitmenke/ProxyHandler.cs
HttpHandler that act as a proxy
public class ProxyHandler : IHttpHandler
{
const string SERVER_URL = "http://dev-server";
#region IHttpHandler Members
public bool IsReusable
{
get { return false; }
}
@mahizsas
mahizsas / web-enable-cors.config.xml
Last active August 29, 2015 14:13
Enable CORS in ASP.NET ( Non Webapi )
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
</customHeaders>
</httpProtocol>
</system.webServer>
@mahizsas
mahizsas / ProfiledRazorViewEngine.cs
Last active August 29, 2015 14:13 — forked from ido-ran/ProfiledRazorViewEngine.cs
Razor mini profiler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using StackExchange.Profiling;
namespace MiniProfiler.Razor {
public class ProfiledRazorViewEngine : RazorViewEngine {