【发布时间】:2014-09-04 15:58:50
【问题描述】:
我正在尝试根据当前活动的租户返回一个视图,但它不起作用。由于某些原因 settings.Name 为空,即使它应该包含租户站点的名称。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orchard.Themes;
using Orchard.Environment.Configuration;
namespace Speedbump.Controllers
{
public class SpeedBumpController : Controller
{
[Themed]
public ActionResult Index(ShellSettings settings)
{
//Initialize Variables
string requestedURL = "";
string finalRequestedURL = "";
bool wasValidURL = false;
//Grab the query string parameters and put them into variables to be used later
//Requested URL
requestedURL = Request.QueryString["url"];
//Remove "http://" or "https://" from the Requested URL (if it exists)
if (requestedURL.IndexOf("http") > -1)
{
finalRequestedURL = requestedURL.Replace("http://", "");
}
else if (requestedURL.IndexOf("https") > -1)
{
finalRequestedURL = requestedURL.Replace("https://", "");
}
else
{
finalRequestedURL = requestedURL;
}
//Create a list of strings to contain all the "valid" URLs
var whiteList = new List<string>();
//Add URLs to the list
whiteList.Add("www.google.com");
whiteList.Add("www.gmail.com");
//Loop through each URL in the list of Valid URLs checking against the finalRequestedURL
foreach (string validURL in whiteList)
{
if (finalRequestedURL == validURL)
{
wasValidURL = true;
break;
}
wasValidURL = false;
}
//ViewBag Items
ViewBag.wasValidURL = wasValidURL;
ViewBag.requestedURL = finalRequestedURL;
ViewBag.tenantName = settings.Name;
//Return a different view depending on whether or not the url is valid
if (wasValidURL)
{
if (!string.IsNullOrEmpty(settings.Name))
{
return View(settings.Name + "ValidURL");
}
else
{
return View("ValidURL");
}
}
else
{
if (!string.IsNullOrEmpty(settings.Name))
{
return View(settings.Name + "InvalidURL");
}
else
{
return View("InvalidURL");
}
}
}
}
}
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: module controller views orchardcms