2014-07-16 20:35:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
|
using System.Web.Routing;
|
2014-10-25 23:54:19 +02:00
|
|
|
|
using Yavsc.Formatters;
|
2015-01-29 20:59:50 +01:00
|
|
|
|
using Yavsc.Model.FrontOffice;
|
2015-02-12 16:08:16 +01:00
|
|
|
|
using System.Web.Http;
|
2015-02-17 13:57:39 +01:00
|
|
|
|
using System.Web.SessionState;
|
2014-07-16 20:35:03 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Yavsc
|
|
|
|
|
|
{
|
2015-02-17 13:57:39 +01:00
|
|
|
|
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Mvc application.
|
|
|
|
|
|
/// </summary>
|
2014-07-16 20:35:03 +02:00
|
|
|
|
public class MvcApplication : System.Web.HttpApplication
|
|
|
|
|
|
{
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Registers the routes.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="routes">Routes.</param>
|
2014-07-16 20:35:03 +02:00
|
|
|
|
public static void RegisterRoutes (RouteCollection routes)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");
|
2014-12-20 02:11:51 +01:00
|
|
|
|
routes.IgnoreRoute ("Scripts/{*pathInfo}");
|
2014-10-20 07:23:44 +02:00
|
|
|
|
routes.IgnoreRoute ("Theme/{*pathInfo}");
|
|
|
|
|
|
routes.IgnoreRoute ("images/{*pathInfo}");
|
2015-02-17 13:57:39 +01:00
|
|
|
|
routes.IgnoreRoute ("users/{*pathInfo}");
|
|
|
|
|
|
routes.IgnoreRoute ("files/{*pathInfo}");
|
|
|
|
|
|
routes.IgnoreRoute ("avatars/{*pathInfo}");
|
2015-01-27 00:41:20 +01:00
|
|
|
|
routes.IgnoreRoute ("xmldoc/{*pathInfo}"); // xml doc
|
|
|
|
|
|
routes.IgnoreRoute ("htmldoc/{*pathInfo}"); // html doc
|
2015-02-04 15:45:21 +01:00
|
|
|
|
routes.IgnoreRoute ("favicon.ico");
|
|
|
|
|
|
routes.IgnoreRoute ("favicon.png");
|
|
|
|
|
|
routes.IgnoreRoute ("robots.txt");
|
2014-07-16 20:35:03 +02:00
|
|
|
|
routes.MapRoute (
|
|
|
|
|
|
"Blog",
|
|
|
|
|
|
"Blog/{user}/{title}",
|
|
|
|
|
|
new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional }
|
2015-02-10 13:27:10 +01:00
|
|
|
|
);
|
|
|
|
|
|
routes.MapRoute (
|
|
|
|
|
|
"Blogs",
|
|
|
|
|
|
"Blogs/{action}/{user}/{title}",
|
|
|
|
|
|
new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional }
|
|
|
|
|
|
);
|
2015-04-15 03:03:20 +02:00
|
|
|
|
routes.MapRoute (
|
|
|
|
|
|
"Account",
|
|
|
|
|
|
"Account/{action}/{user}",
|
|
|
|
|
|
new { controller = "Account", action = "Index", user=UrlParameter.Optional }
|
|
|
|
|
|
);
|
2014-07-16 20:35:03 +02:00
|
|
|
|
routes.MapRoute (
|
|
|
|
|
|
"Default",
|
2015-02-10 13:27:10 +01:00
|
|
|
|
"{controller}/{action}/{user}/{title}",
|
|
|
|
|
|
new { controller = "Blogs", action = "Index", user=UrlParameter.Optional, title = UrlParameter.Optional }
|
2014-07-16 20:35:03 +02:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2015-02-12 16:08:16 +01:00
|
|
|
|
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// <summary>
|
2015-02-12 16:08:16 +01:00
|
|
|
|
/// Starts the Application.
|
2015-01-27 00:41:20 +01:00
|
|
|
|
/// </summary>
|
2014-07-16 20:35:03 +02:00
|
|
|
|
protected void Application_Start ()
|
|
|
|
|
|
{
|
|
|
|
|
|
AreaRegistration.RegisterAllAreas ();
|
2015-02-17 13:57:39 +01:00
|
|
|
|
WebApiConfig.Register (GlobalConfiguration.Configuration);
|
2014-07-16 20:35:03 +02:00
|
|
|
|
RegisterRoutes (RouteTable.Routes);
|
|
|
|
|
|
}
|
2015-02-17 13:57:39 +01:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Applications the post authorize request.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected void Application_PostAuthorizeRequest()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsWebApiRequest())
|
|
|
|
|
|
{
|
|
|
|
|
|
HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsWebApiRequest()
|
|
|
|
|
|
{
|
|
|
|
|
|
return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith(WebApiConfig.UrlPrefixRelative);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-16 20:35:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|