Created
July 18, 2011 04:35
-
-
Save amokan/1088552 to your computer and use it in GitHub Desktop.
Example AuthorizeFilter and session model for checking the domain of a request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace MvcTest.Models | |
{ | |
/// <summary> | |
/// simple class for storing the domain/group info of the current | |
/// httpContext | |
/// </summary> | |
public class DomainSession | |
{ | |
public int DomainId { get; set; } | |
public string DomainName { get; set; } | |
public int GroupId { get; set; } | |
public DateTime? LoginDate { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
using System.Web.Routing; | |
using MvcTest.Infrastructure.Filters; | |
namespace MvcTest | |
{ | |
public class MvcApplication : System.Web.HttpApplication | |
{ | |
/// <summary> | |
/// name of the session key to store the serialized DomainSession object | |
/// </summary> | |
public static string DomainSessionKey = "MyApp_DomainSession"; | |
/// <summary> | |
/// register certain filters globally | |
/// </summary> | |
/// <param name="filters"></param> | |
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | |
{ | |
filters.Add(new HandleErrorAttribute()); | |
filters.Add(new DomainAuthorize()); | |
} | |
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | |
routes.MapRoute( | |
"Default", // Route name | |
"{controller}/{action}/{id}", // URL with parameters | |
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults | |
); | |
} | |
protected void Application_Start() | |
{ | |
AreaRegistration.RegisterAllAreas(); | |
RegisterGlobalFilters(GlobalFilters.Filters); | |
RegisterRoutes(RouteTable.Routes); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment