Files
Umbraco-CMS/src/Umbraco.Web.Common/Attributes/PluginControllerAttribute.cs

33 lines
990 B
C#
Raw Normal View History

using Microsoft.AspNetCore.Mvc;
2020-04-20 12:20:47 +02:00
namespace Umbraco.Cms.Web.Common.Attributes;
/// <summary>
/// Indicates that a controller is a plugin controller and will be routed to its own area.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class PluginControllerAttribute : AreaAttribute
2020-04-20 12:20:47 +02:00
{
/// <summary>
/// Initializes a new instance of the <see cref="PluginControllerAttribute" /> class.
2020-04-20 12:20:47 +02:00
/// </summary>
/// <param name="areaName"></param>
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)))
2020-04-20 12:20:47 +02:00
{
throw new FormatException(
$"Invalid area name \"{areaName}\": the area name can only contains letters and digits.");
2020-04-20 12:20:47 +02:00
}
AreaName = areaName;
2020-04-20 12:20:47 +02:00
}
/// <summary>
/// Gets the name of the area.
/// </summary>
public string AreaName { get; }
2020-04-20 12:20:47 +02:00
}