I guess this is a common problem: you need to have different web site layout for unauthenticated users. In simple cases this is very easy: just use masterPageFile attribute on views. But it gets more complex when you have views that are used in both authenticated and unauthenticated context. Luckily MVC lets you plug into almost anything, and this can be solved with an action filter like this:

using System.Web.Mvc;
/// <summary>
/// A globally registered attribute to change view master 
/// page based on whether user is authenticated or not. 
/// Uses magic strings for the file names, could 
/// be changed to something more elegant.
/// </summary>
public sealed class SwitchMasterPageFilter : IActionFilter
    public void OnActionExecuting(
        ActionExecutingContext filterContext)
    public void OnActionExecuted(
        ActionExecutedContext filterContext)
        var result = filterContext.Result as ViewResult;
        if (result != null)
            bool authenticated = filterContext.HttpContext
            result.MasterName = authenticated ? 
              : "~/Views/Shared/SiteUnauthenticated.master";

Remember to register the filter on your site bootstrapper and you are good to go.

Using Protocol buffers v3 with ASP.NET core

This blog post gives a working Input and Output formatters for ASP.NET MVC to work with Google Protocol Buffers. Continue reading

Don't let techies design game user experience

Published on February 02, 2016

Using VS Team Services with go get

Published on January 19, 2016