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

32 lines
1.1 KiB
C#
Raw Normal View History

using System;
2020-04-20 12:20:47 +02:00
using System.Linq;
using Microsoft.AspNetCore.Mvc;
2020-04-20 12:20:47 +02:00
namespace Umbraco.Cms.Web.Common.Attributes
2020-04-20 12:20:47 +02:00
{
/// <summary>
/// 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)]
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>
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; }
}
}