Skip to content

Instantly share code, notes, and snippets.

View mahizsas's full-sized avatar

MAHIZ mahizsas

View GitHub Profile
using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Mvc;
namespace UmbMvcMiniProfiler
{
public class Bootstrapper : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class PartialAppPlayground
{
public static void Initialize()
{
Func<IDbConnection> createConnection = () => new SqlConnection();
/// <summary>
/// Reads the Request body into a string/byte[] and
/// assigns it to the parameter bound.
///
/// Should only be used with a single parameter on
/// a Web API method using the [NakedBody] attribute
/// </summary>
public class NakedBodyParameterBinding : HttpParameterBinding
{
public NakedBodyParameterBinding(HttpParameterDescriptor descriptor)
using System.Web.Mvc;
namespace DemoApp.Areas.Demo
{
public class DemoAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
<!DOCTYPE HTML>
<html ng-app="ChinookApp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
<script src="libs/angular-resource.min.js"></script>
<script src="app.js" type="text/javascript"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
<link rel="stylesheet" href="app.css">
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Web;
using FakeHost;
using FluentAssertions;
using HtmlAgilityPack;
using NUnit.Framework;
using System.Threading.Tasks;
using System.Web.Mvc;
using JetBrains.Annotations;
using ShortBus;
public abstract class BaseController : Controller
{
public IMediator Mediator { get; set; }
protected Response<TResult> Query<TResult>(IQuery<TResult> query)
/* A JSON gzip compression filter, which could easily be adapted to any pattern needed. This uses a custom AfterFilter
* type which is just a fancy wrapper of Action<NancyContext>. It's useful for convention based loading of filters
*/
public class GzipCompressionFilter : AfterFilter
{
protected override void Handle(NancyContext ctx)
{
if ((ctx.Response.ContentType == "application/json") && ctx.Request.Headers.AcceptEncoding.Any(
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
public static class ModelStateDictionaryExtensions
{
public static IEnumerable<string> ToErrors(this ModelStateDictionary dict)
{
return dict.OrderBy(kvp => kvp.Key)

Owin Authentication with Web API 2

Using Microsoft.Owin.Security along with .NET Web API 2 for authentication on Single Page Applications.

My example is split up into 2 different projects, API which is WebAPI2 project and MyProj which is a basic MVC that contains primarily only JavaScript/CSS/etc and the startup classes.

API > AccountController.cs

namespace API

{