0

I am using the following code to achieve something like domain.com/actionName1, domain.com/actionName2 and so on to reach actions that reside in home controller.

routes.MapRouteLowercase("DefaultRoutes",
             "{action}",
             new { controller = "Home" },
             new { action = new homeActionConstraint() });

It works fine. But how do I stop user from entering domain.com/home/actionName1 etc. and still reaching the action instead of 404 or something?

2
  • why would you want it to 404? Commented Feb 13, 2012 at 0:51
  • @nathangonzalez not necessarily 404 maybe. maybe 301 or something. Commented Feb 13, 2012 at 1:10

2 Answers 2

2

You need to remove the default {controller}/{action}/{id} route that matches that URL.
(or constrain it to not match)

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

4 Comments

but I do need the default {controller}/{action}. Just not for home controller.
@progtick: Then you can add a constraint.
You could also make a separate route redirecting Home/{action} to {action}.
@SLaks ... which of course should be defined before the default route (controller/action/id) definition.
1

take out the default route, just delete it and everything will stop working the normal way or you can map the default root to the 404 page you desire, however that is a little strange even for SO

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.