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 8385177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:36:16+00:00 2026-06-09T17:36:16+00:00

I have a performance issue with a fairly simple ASP.MVC view. It’s a log-on

  • 0

I have a performance issue with a fairly simple ASP.MVC view.

It’s a log-on page that should be almost instant, but is taking about half a second.

After a lot of digging it looks like the problem is the first call the Url.Action – it’s taking around 450ms (according to MiniProfiler) but that seems insanely slow.

Subsequent calls to Url.Action are taking <1ms, which is more in line with what I would expect.

This is consistent whether I use Url.Action("action", "controller") or Url.Action("action"), but doesn’t seem to happen if I use Url.Content("~/controller/action"). This also happens when I call Html.BeginForm("action").

Does anyone have any idea what’s causing this?

A dig into the source suggests that RouteCollection.GetVirtualPath might be the culprit, as that’s common to both Url.Action and Html.BeginForm. However, surely that’s used all over the place? I mean, ½ a second is far too slow.

I have 20 or so custom routes (it’s a fairly large app with some legacy WebForms pages) but even then the times seem far too slow.

Any ideas how to fix it?

  • 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-09T17:36:18+00:00Added an answer on June 9, 2026 at 5:36 pm

    Problem found, and it is with the routing tables (cheers Kirill).

    Basically we have lots of routes that look something like this:

    string[] controllers = GetListOfValidControllers();
    
    routes.MapRoute(
        name: GetRouteName(),
        url: subfolder + "/{controller}/{action}/{id}",
        defaults: new { action = "Index", id = UrlParameter.Optional },
        constraints: new { controller = "(" + string.Join("|", controllers) + ")" });
    

    It turns out that the Regex check is very slow, painfully slow. So I replaced it with an implementation of IRouteConstraint that just checks against a HashSet instead.

    Then I changed the map route call:

    routes.MapRoute(
        name: GetRouteName(),
        url: subfolder + "/{controller}/{action}/{id}",
        defaults: new { action = "Index", id = UrlParameter.Optional },
        constraints: new { controller = new HashSetConstraint(controllers) });
    

    I also used the RegexConstraint mentioned in that linked article for anything more complicated – including lots of calls like this (because we have legacy WebForm pages):

    routes.IgnoreRoute(
        url: "{*allaspx}", 
        constraints: new { allaspx = new RegexConstraint( @".*\.as[pmh]x(/.*)?") });
    

    Those two simple changes completely fix the problem; Url.Action and Html.BeginForm now take a negligible amount of time (even with lots of routes).

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

Sidebar

Related Questions

I have several performance issue in my website. I'm using asp.net mvc 2 and
I have a performance issue regarding a quite simple query that run for more
i have a performance issue in my tableview my cellForRow looks like that: if
I have a quite serious performance issue with the following statement that i can't
I am running into some performance issue with php and mysql page. i have
Just like in this topic , I have a performance issue in dev mode
I've got an performance issue in my application using a MSSQL DB. I have
I have just migrated to mysql 5.5.20 and I had a performance issue with
I have problem with my widget related to performance and memory: Issue : My
I have a jQueryMobile site/app where performance is an issue. I am reading a

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.