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

  • Home
  • SEARCH
  • 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 8967249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:12:01+00:00 2026-06-15T17:12:01+00:00

I have this simple User Area in my MVC 4 project. public class UserAreaRegistration

  • 0

I have this simple User Area in my MVC 4 project.

public class UserAreaRegistration : AreaRegistration
{
    public override string AreaName { get { return "User"; } }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute("User_Constraint",
                "{userName}/{controller}/{action}/{id}",
                new { userName = string.Empty, controller = "Products", action = "Index", id = UrlParameter.Optional },
                new { userName = new UserNameRouteConstraint() },
                new[] { "T2b.Web.Areas.User.Controllers" }
            );
    }
}

To make sure the User Name exists I have a RouteConstraint called UserNameRouteConstraint()

All this does is a simple lookup in my users table and return true if the user has been found.

So far so good, this construction works fine!

Now; My view in the User Area has the following line of code

@Html.ActionLink("More information", "details", new {id = product.Guid})

This single line causes the UserNameRouteConstraint() to be called….

How and why!? If I write the link in plain HTML (see example below) it works well, but I want to keep to the MVC Principles as close as possible.

<a href="/username/Products/details/@product.Guid">More information</a>

Is there any way to prevent the RouteConstraint call?

  • 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-15T17:12:02+00:00Added an answer on June 15, 2026 at 5:12 pm

    Whenever routes are generated the constraints are processed.

    You can add this check to stop the constraint depending on whether the constraint is handling an incoming request or generating a URL from a function like ActionLink:

    public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
    {
        if(routeDirection == RouteDirection.UrlGeneration)
            return false;
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy. I have a very simple user control: public int?
I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end
In my web admin area I have using very simple logic: session_start(); ob_start(); if(!isset($_SESSION['user'])){
I'm a beginner in jQuery area and I have simple question like this :
I have a simple application where a user clicks on an area, and the
I have this simple code in my user_controller.rb file #listing all users def index
I have this simple piece of code : int a = 1, b =
I have this simple code (for making things shorted, the important bits are probably
I have this simple redirection on my website and it does not rewrite my
I have this simple rule in my Makefile : PP=g++ -std=c++0x %.o: $.cpp $(PP)

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.