UrlUtil.cs 728 B

1234567891011121314151617181920212223242526272829303132
  1. // <author></author>
  2. // <date></date>
  3. // <description></description>
  4. using System.Text.RegularExpressions;
  5. namespace ERP.Framework.Utils
  6. {
  7. public class UrlUtil
  8. {
  9. public static bool Match(string route, List<string> whiteList)
  10. {
  11. if (!route.EndsWith("/"))
  12. {
  13. route += "/";
  14. }
  15. foreach (var pattern in whiteList)
  16. {
  17. var regexPattern = "^" + Regex.Escape(pattern).Replace("\\*", ".*") + "$";
  18. var regex = new Regex(regexPattern);
  19. if (regex.IsMatch(route))
  20. {
  21. return true;
  22. }
  23. }
  24. return false;
  25. }
  26. }
  27. }