Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:53:42+00:00 2026-06-13T09:53:42+00:00

I have the following route: context.MapRoute( content, {page}/{title}, new { controller = Server, action

  • 0

I have the following route:

context.MapRoute(
    "content",
    "{page}/{title}",
    new { controller = "Server", action = "Index" },
    new { page = @"^[AFL][0-9A-Z]{4}$" }
);

This route is used for pages such as:

/A1234
/F6789
/L0123

However it also catches: /Admin which is something I do not want.

I put a temporary solution in place that looks like this:

context.MapRoute(
    "content",
    "{page}/{title}",
    new { controller = "Server", action = "Index" },
    new { page = @"^[AFL][0-9][0-9A-Z]{3}$" }
);

This only works because right now all my pages have a 0 in the second digit.

Is there a way I could configure my route to accept A,F or L followed by 4 upper case characters but have it not catch “dmin” ?

Not sure if this is the case but I am thinking the regular expression should not accept “dmin” as it’s in lower case and I only specify A-Z. However when used as an MVC route it does take “dmin”. Does anyone know if ASP MVC internally converts this to all uppercase?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:53:43+00:00Added an answer on June 13, 2026 at 9:53 am

    Solution 1: Custom route constraint class

    Default route processing ignores case (see code below) when matching URLs that’s why Admin in your case matches as well. All you should do is to write a custom route constraint class that implements IRouteConstraint interface and implement Match method appropriately to be case sensitive.

    Here’s a tutorial to get you started

    Solution 2: Custom Route class

    If you look at how default Route class processes constraints, this is the code:

    protected virtual bool ProcessConstraint(HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        IRouteConstraint routeConstraint = constraint as IRouteConstraint;
    
        // checks custom constraint class instances
        if (routeConstraint != null)
        {
            return routeConstraint.Match(httpContext, this, parameterName, values, routeDirection);
        }
    
        // No? Ok constraint provided as regular expression string then?
        string text = constraint as string;
        if (text == null)
        {
            throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, SR.GetString("Route_ValidationMustBeStringOrCustomConstraint"), new object[]
            {
                parameterName,
                this.Url
            }));
        }
        object value;
        values.TryGetValue(parameterName, out value);
        string input = Convert.ToString(value, CultureInfo.InvariantCulture);
        string pattern = "^(" + text + ")$";
    
        // LOOK AT THIS LINE
        return Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant);
    }
    

    The last line actually matches provided regular expression route constraints. As you can see it ignores case. So the second possible solution is to write a new Route class that inherits from this default Route class and override ProcessConstraint method to not ignore case. Everything else can then stay the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following route set up: context.MapRoute( MyAccount_default, MyAccount/{controller}/{action}/{id}, new { action =
I currently have the following route set up: context.MapRoute(Root, , new { controller =
I have the following routes set up: context.MapRoute( content_article, A{rk}/{title}, new { controller =
If I have the following route defined in my only area:- context.MapRoute( Search_default, Search/{controller}/{action}/{id},
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have the following route defined: routes.MapRoute(name: StateResults, url: {state}/{searchTerm}, defaults: new { controller
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have the following URl: http://localhost:12981/BaseEvent/EventOverview/12?type=Film This is route: routes.MapRoute( Default, // Route name
I have the following routes in my app: GET /admin/comments(.:format) {:controller=>admin/comments, :action=>index} admin_comments POST
I have the following route's defined: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute({resource}.axd/{*pathInfo}); routes.MapRoute(

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.