Skip to content

Instantly share code, notes, and snippets.

public class ErrorController : Controller
{
public ILogger Logger { get; set; }
public ActionResult Error(int code = 404, string redirectedUrl = "")
{
ViewBag.StateCode = code;
if (code == 401)
if (!string.IsNullOrEmpty(redirectedUrl))
return Redirect(redirectedUrl);
public class MvcErrorAttribute : HandleErrorAttribute
{
public ILogger Logger { get; set; }
public ErrorController ErrorController { get; set; }
public MvcErrorAttribute()
{ }
public override void OnException(ExceptionContext filterContext)
{
@imwower
imwower / ErrorHandlerModule
Created July 30, 2014 03:06
ASP MVC Error Handler Module
public class ErrorHandlerModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
builder.RegisterType<MvcErrorAttribute>()
.As<HandleErrorAttribute>()
.PropertiesAutowiredWithParameters();
@imwower
imwower / Bootstrapper
Created July 30, 2014 02:53
Autofac Bootstrapper
public class Bootstrapper
{
public Bootstrapper()
{ }
private ContainerBuilder builder;
private IContainer container;
public IContainer Container
{
@imwower
imwower / MvcApplication
Created July 30, 2014 02:49
ASP MVC Application
public class MvcApplication : HttpApplication
{
public MvcApplication()
{ }
void Application_Error(object sender, EventArgs e)
{
var httpContext = ((MvcApplication)sender).Context;
var exception = Server.GetLastError();
@imwower
imwower / AutofacExtensions
Last active August 29, 2015 14:04
Special autowiring mode that also scans Resolve parameters while wiring properties
{
public static class AutofacExtensions
{
/// <summary>
/// Special autowiring mode that also scans Resolve parameters while wiring properties
/// </summary>
public static IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> PropertiesAutowiredWithParameters<TLimit, TActivatorData, TRegistrationStyle>(this IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> rb)
{
AutowiringPropertyInjectorWithParameters injector = new AutowiringPropertyInjectorWithParameters();
rb.RegistrationData.ActivatingHandlers.Add(delegate(object s, ActivatingEventArgs<object> e)
using Microsoft.Phone.Controls;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
namespace Ocell.Controls
@imwower
imwower / AsyncImageHelper
Created June 30, 2014 01:56
async image
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
using Windows.Storage;
@imwower
imwower / FTPHelper
Created June 21, 2014 09:45
C# FTP Helper
public class FileService : IFileService.IFileService
{
private readonly string ftpUserName;
private readonly string ftpPassword;
private readonly string ftpRootPath;
public ILogger Logger { get; set; }
public FileService(string user, string password, string server)
{
this.ftpUserName = user;
try
{
string source = "1.png";
WebClient client = new WebClient();
NetworkCredential nc = new NetworkCredential("test", "test");
Uri addy = new Uri(@"\\192.168.57.182\Upload\" + source);
client.Credentials = nc;
byte[] arrReturn = client.UploadFile(addy, "1.png");
}
catch (Exception e)