Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/System.Web.Mvc/MvcRouteHandler.cs')
-rw-r--r--src/System.Web.Mvc/MvcRouteHandler.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/System.Web.Mvc/MvcRouteHandler.cs b/src/System.Web.Mvc/MvcRouteHandler.cs
new file mode 100644
index 00000000..4b898b2c
--- /dev/null
+++ b/src/System.Web.Mvc/MvcRouteHandler.cs
@@ -0,0 +1,47 @@
+using System.Web.Mvc.Properties;
+using System.Web.Routing;
+using System.Web.SessionState;
+
+namespace System.Web.Mvc
+{
+ public class MvcRouteHandler : IRouteHandler
+ {
+ private IControllerFactory _controllerFactory;
+
+ public MvcRouteHandler()
+ {
+ }
+
+ public MvcRouteHandler(IControllerFactory controllerFactory)
+ {
+ _controllerFactory = controllerFactory;
+ }
+
+ protected virtual IHttpHandler GetHttpHandler(RequestContext requestContext)
+ {
+ requestContext.HttpContext.SetSessionStateBehavior(GetSessionStateBehavior(requestContext));
+ return new MvcHandler(requestContext);
+ }
+
+ protected virtual SessionStateBehavior GetSessionStateBehavior(RequestContext requestContext)
+ {
+ string controllerName = (string)requestContext.RouteData.Values["controller"];
+ if (String.IsNullOrWhiteSpace(controllerName))
+ {
+ throw new InvalidOperationException(MvcResources.MvcRouteHandler_RouteValuesHasNoController);
+ }
+
+ IControllerFactory controllerFactory = _controllerFactory ?? ControllerBuilder.Current.GetControllerFactory();
+ return controllerFactory.GetControllerSessionBehavior(requestContext, controllerName);
+ }
+
+ #region IRouteHandler Members
+
+ IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
+ {
+ return GetHttpHandler(requestContext);
+ }
+
+ #endregion
+ }
+}