- Add Area scenario is now working. Areas added via MVC 2 RC 2 VS Tooling are discovered/loaded as Orchard modules.

- Html.AddRenderAction to permit controller actions to display views in zones.
- Disabling the always on AntiForgery filter (will make it optional probably).

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-03-03 17:39:24 -08:00
parent 5a6d0f3bc0
commit ca477238f1
8 changed files with 93 additions and 2 deletions

View File

@@ -5,7 +5,7 @@
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{50B779EA-EC00-4699-84C0-03B395C365D2}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Orchard.Web</RootNamespace>

View File

@@ -60,7 +60,7 @@ namespace Orchard.Data {
public ISessionFactory GetSessionFactory() {
lock (this) {
if (_sessionFactory == null) {
_sessionFactory = BuildSessionFactory(false /*createDatabase*/, false /*updateSchema*/);
_sessionFactory = BuildSessionFactory(false /*createDatabase*/, true /*updateSchema*/);
}
}
return _sessionFactory;

View File

@@ -18,6 +18,7 @@ namespace Orchard.Mvc.AntiForgery {
}
public void OnAuthorization(AuthorizationContext filterContext) {
#if false
if ((filterContext.HttpContext.Request.HttpMethod != "POST" ||
_authenticationService.GetAuthenticatedUser() == null) && !ShouldValidateGet(filterContext)) {
return;
@@ -29,6 +30,7 @@ namespace Orchard.Mvc.AntiForgery {
if (filterContext.HttpContext is HackHttpContext)
filterContext.HttpContext = ((HackHttpContext)filterContext.HttpContext).OriginalHttpContextBase;
#endif
}
private static bool ShouldValidateGet(AuthorizationContext context) {

View File

@@ -8,6 +8,7 @@ using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
using Orchard.Extensions;
using Orchard.Mvc.ViewModels;
using Orchard.Services;
using Orchard.Settings;
using Orchard.Utility;
@@ -297,5 +298,38 @@ namespace Orchard.Mvc.Html {
}
#endregion
#region AddRenderAction
public static void AddRenderAction(this HtmlHelper html, string location, string actionName) {
AddRenderActionHelper(html, location, actionName, null/*controllerName*/, null);
}
public static void AddRenderAction(this HtmlHelper html, string location, string actionName, object routeValues) {
AddRenderActionHelper(html, location, actionName, null/*controllerName*/, new RouteValueDictionary(routeValues));
}
public static void AddRenderAction(this HtmlHelper html, string location, string actionName, RouteValueDictionary routeValues) {
AddRenderActionHelper(html, location, actionName, null/*controllerName*/, routeValues);
}
public static void AddRenderAction(this HtmlHelper html, string location, string actionName, string controllerName) {
AddRenderActionHelper(html, location, actionName, controllerName, null/*RouteValueDictionary*/);
}
public static void AddRenderAction(this HtmlHelper html, string location, string actionName, string controllerName, object routeValues) {
AddRenderActionHelper(html, location, actionName, controllerName, new RouteValueDictionary(routeValues));
}
public static void AddRenderAction(this HtmlHelper html, string location, string actionName, string controllerName, RouteValueDictionary routeValues) {
AddRenderActionHelper(html, location, actionName, controllerName, routeValues);
}
private static void AddRenderActionHelper(this HtmlHelper html, string location, string actionName, string controllerName, RouteValueDictionary routeValues) {
// Retrieve the "BaseViewModel" for zones if we have one
var baseViewModel = BaseViewModel.From(html.ViewData);
if (baseViewModel == null)
return;
baseViewModel.Zones.AddRenderAction(location, actionName, controllerName, routeValues);
}
#endregion
}
}

View File

@@ -310,7 +310,9 @@
<Compile Include="UI\Zones\IZoneManager.cs" />
<Compile Include="UI\Zones\ContentPartDisplayZoneItem.cs" />
<Compile Include="UI\Zones\ContentPartEditorZoneItem.cs" />
<Compile Include="UI\Zones\RenderActionZoneItem.cs" />
<Compile Include="UI\Zones\RenderPartialZoneItem.cs" />
<Compile Include="UI\Zones\RenderStaticZoneItem.cs" />
<Compile Include="UI\Zones\ZoneCollection.cs" />
<Compile Include="UI\Zones\ZoneEntry.cs" />
<Compile Include="UI\Zones\ZoneItem.cs" />

View File

@@ -0,0 +1,15 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
namespace Orchard.UI.Zones {
public class RenderActionZoneItem : ZoneItem {
public string ActionName { get; set; }
public string ControllerName { get; set; }
public RouteValueDictionary RouteValues { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
html.RenderAction(ActionName, ControllerName, RouteValues);
}
}
}

View File

@@ -0,0 +1,13 @@
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace Orchard.UI.Zones {
public class RenderStaticZoneItem : ZoneItem {
public object Model { get; set; }
public string TemplateName { get; set; }
public override void Execute<TModel>(HtmlHelper<TModel> html) {
html.RenderPartial(TemplateName, Model);
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.ViewModels;
namespace Orchard.UI.Zones {
@@ -15,6 +16,11 @@ namespace Orchard.UI.Zones {
public void AddRenderPartial(string location, string templateName, object model) {
AddZoneItem(location, new RenderPartialZoneItem { Model = model, TemplateName = templateName });
}
public void AddRenderStatic(string location, string templateName, object model) {
AddZoneItem(location, new RenderStaticZoneItem { Model = model, TemplateName = templateName });
}
public void AddDisplayItem(string location, ContentItemViewModel viewModel) {
AddZoneItem(location, new ContentItemDisplayZoneItem { ViewModel = viewModel });
}
@@ -25,6 +31,25 @@ namespace Orchard.UI.Zones {
AddZoneItem(location, new ContentPartEditorZoneItem { Model = model, TemplateName = templateName, Prefix = prefix });
}
public void AddRenderAction(string location, string actionName) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName });
}
public void AddRenderAction(string location, string actionName, object routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, RouteValues = new RouteValueDictionary(routeValues) });
}
public void AddRenderAction(string location, string actionName, RouteValueDictionary routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, RouteValues = routeValues });
}
public void AddRenderAction(string location, string actionName, string controllerName) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, ControllerName = controllerName });
}
public void AddRenderAction(string location, string actionName, string controllerName, object routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, ControllerName = controllerName, RouteValues = new RouteValueDictionary(routeValues) });
}
public void AddRenderAction(string location, string actionName, string controllerName, RouteValueDictionary routeValues) {
AddZoneItem(location, new RenderActionZoneItem { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues });
}
private void AddZoneItem(string location, ZoneItem item) {
string zoneName;
var position = string.Empty;