3

I have a route like this in my global.asax.cs:

        routes.MapRoute(
           "NewsArticles",
           "News/{page}",
           new { controller = "News", action = "Index", archive = false }
       );

How can I restrict access to this route so that it's only encountered if the user uses an integer?

1 Answer 1

5

Make sure you put this route before the default route. You could also use regular expressions to restrict possible parameter values:

routes.MapRoute(
    "NewsArticles",
    "News/{page}",
    new { controller = "News", action = "Index" },
    new { page = @"^\d{1,3}$" }
);

Remark: In your example you are using archive = false while there is no archive parameter defined in the route.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.