2021-02-18 11:06:02 +01:00
|
|
|
|
using System;
|
2020-04-20 12:20:47 +02:00
|
|
|
|
using System.Linq;
|
2021-02-18 11:06:02 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-04-20 12:20:47 +02:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Cms.Web.Common.Attributes
|
2020-04-20 12:20:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2020-05-14 17:04:16 +10:00
|
|
|
|
/// Indicates that a controller is a plugin controller and will be routed to its own area.
|
2020-04-20 12:20:47 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
2020-05-14 17:04:16 +10:00
|
|
|
|
public class PluginControllerAttribute : AreaAttribute
|
2020-04-20 12:20:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="PluginControllerAttribute"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="areaName"></param>
|
2020-05-14 17:04:16 +10:00
|
|
|
|
public PluginControllerAttribute(string areaName) : base(areaName)
|
2020-04-20 12:20:47 +02:00
|
|
|
|
{
|
|
|
|
|
|
// validate this, only letters and digits allowed.
|
|
|
|
|
|
if (areaName.Any(c => !char.IsLetterOrDigit(c)))
|
|
|
|
|
|
throw new FormatException($"Invalid area name \"{areaName}\": the area name can only contains letters and digits.");
|
|
|
|
|
|
|
|
|
|
|
|
AreaName = areaName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the name of the area.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string AreaName { get; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|