Initial commit: JDE Scoping Tool migration project
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
This commit is contained in:
Executable
+73
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using DeviceDetectorNET;
|
||||
using DeviceDetectorNET.Parser;
|
||||
using DeviceDetectorNET.Results;
|
||||
|
||||
namespace WebInterface.Filters
|
||||
{
|
||||
/// <summary>
|
||||
/// Browser user agent action filter
|
||||
/// </summary>
|
||||
public class UserAgentFilter : IActionFilter
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private const string INVALID_UA_CONTROLLER = "INVALIDUA";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private const string INVALID_UA_ACTION = "INVALIDUSERAGENT";
|
||||
|
||||
/// <summary>
|
||||
/// List of valid user agents
|
||||
/// </summary>
|
||||
private static string[] VALID_USER_AGENTS = new string[] { };
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public UserAgentFilter()
|
||||
{
|
||||
DeviceDetectorNET.DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);
|
||||
DeviceDetectorSettings.RegexesDirectory = HostingEnvironment.MapPath("~/bin/");
|
||||
|
||||
VALID_USER_AGENTS = WebConfigurationManager.AppSettings["ValidUserAgents"].ToUpper().Split(',');
|
||||
}
|
||||
|
||||
/// <summary>Called before an action method executes.</summary>
|
||||
/// <param name="filterContext">The filter context.</param>
|
||||
public void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
string requestedController = filterContext.RequestContext.RouteData.Values["controller"].ToString().ToUpper();
|
||||
string requestedAction = filterContext.RequestContext.RouteData.Values["action"].ToString().ToUpper();
|
||||
|
||||
DeviceDetectorResult userAgent = DeviceDetectorNET.DeviceDetector.GetInfoFromUserAgent(filterContext.RequestContext.HttpContext.Request.UserAgent).Match;
|
||||
string browserFamily = userAgent.BrowserFamily;
|
||||
|
||||
if (!VALID_USER_AGENTS.Contains(browserFamily.ToUpper()) && !(INVALID_UA_CONTROLLER.Equals(requestedController) && INVALID_UA_ACTION.Equals(requestedAction)))
|
||||
{
|
||||
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", INVALID_UA_CONTROLLER }, { "action", INVALID_UA_ACTION } });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Called after the action method executes.</summary>
|
||||
/// <param name="filterContext">The filter context.</param>
|
||||
public void OnActionExecuted(ActionExecutedContext filterContext)
|
||||
{
|
||||
//Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user