3
레시피에서 다음 별칭을 만들고 싶습니다. 과수원의 레서피에서 별칭 만들기
using Orchard;
using Orchard.Alias;
using Orchard.Commands;
using System;
using Orchard.Environment;
using System.Linq;
namespace Contrib.Foundation.Common.Commands
{
public class AliasCommands : DefaultOrchardCommandHandler
{
private readonly Work<WorkContext> _workContext;
private readonly IAliasService _aliasService;
public AliasCommands(Work<WorkContext> workContext, IAliasService aliasService,
IOrchardServices orchardServices)
{
_workContext = workContext;
_aliasService = aliasService;
Services = orchardServices;
}
public IOrchardServices Services { get; private set; }
[OrchardSwitch]
public string AliasPath { get; set; }
[OrchardSwitch]
public string RoutePath { get; set; }
[CommandName("alias add")]
[CommandHelp("alias add /AliasPath:<alias-path> /RoutePath:<route-path>\r\n\t" + "Add a new alias")]
[OrchardSwitches("AliasPath,RoutePath")]
public void Add()
{
AliasPath = AliasPath.TrimStart('/', '\\');
if (String.IsNullOrWhiteSpace(AliasPath))
{
AliasPath = "/";
}
if (String.IsNullOrWhiteSpace(RoutePath))
{
Context.Output.WriteLine(T("Route can't be empty"));
return;
}
if (CheckAndWarnIfAliasExists(AliasPath))
{
Context.Output.WriteLine(T("Alias already exist"));
return;
}
try
{
_aliasService.Set(AliasPath, RoutePath, "Custom");
}
catch (Exception ex)
{
Services.TransactionManager.Cancel();
Context.Output.WriteLine(T("An error occured while creating the alias {0}: {1}. Please check the values are correct.", AliasPath, ex.Message));
return;
}
Context.Output.WriteLine(T("Alias {0} created.", AliasPath));
}
private string GetExistingPathForAlias(string aliasPath)
{
var routeValues = _aliasService.Get(aliasPath.TrimStart('/', '\\'));
if (routeValues == null) return null;
return _aliasService.LookupVirtualPaths(routeValues, _workContext.Value.HttpContext)
.Select(vpd => vpd.VirtualPath)
.FirstOrDefault();
}
private bool CheckAndWarnIfAliasExists(string aliasPath)
{
var routePath = GetExistingPathForAlias(aliasPath);
if (routePath == null) return false;
return true;
}
}
}
당신은 다음과 같은 조리법에서 사용할 수 있습니다 :
<Command>
alias add /AliasPath:"/" /RoutePath:"mycontroller"
</Command>
을
좀 더 구체적으로 기재 할 수 있습니까? 어떤 요리법? 나는 이것을 할 수있는 제조법 단계가 있다고 생각하지 않으며 별칭은 내용 항목이 아니며 본질적으로 가져올 수있는 것이 아닙니다. 아마도 당신 자신의 명령이나 레서피 단계를 작성해야 할 것입니다. –
내가 진정으로 원하는 것은 일반적인 페이지가 아닌 사용자 정의 모듈의 특정 컨트롤러와 동작에 대한 기본 페이지 포인트를 갖는 것입니다. – carrier
@carrier 나는 똑같이하려고 노력하고있다. 이것을 달성하기위한 방법이나 방법을 찾아 냈습니까? – Darlene