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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:13:58+00:00 2026-05-13T19:13:58+00:00

Can anyone help me how to optimize this method? public override VirtualPathData GetVirtualPath(RequestContext requestContext,

  • 0

Can anyone help me how to optimize this method?

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
    VirtualPathData path = base.GetVirtualPath(requestContext, values);

    if (path != null)
    {
        string virtualPath = path.VirtualPath;
        string condition = string.Empty;

        if (virtualPath.Contains("?"))
        {
            condition = virtualPath.Substring(virtualPath.IndexOf("?"));
            virtualPath = virtualPath.Substring(0, virtualPath.IndexOf("?"));
        }

        virtualPath = virtualPath.Replace(@"%C5%BD", "ž");
        virtualPath = virtualPath.Replace(@"%C4%90", "đ");
        virtualPath = virtualPath.Replace(@"%C4%86", "ć");
        virtualPath = virtualPath.Replace(@"%C4%8C", "č");
        virtualPath = virtualPath.Replace(@"%C5%A0", "š");

        virtualPath = virtualPath.ToLower().Replace(",", "-").Replace("%20", "-").Replace("&", "-");
        virtualPath = virtualPath.Replace(@"-amp;", "&");

        while (virtualPath.Contains("--"))
        {
            virtualPath = virtualPath.Replace("--", "-");
        }

        path.VirtualPath = virtualPath + condition;
    }

    return path;
}
  • 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-05-13T19:13:58+00:00Added an answer on May 13, 2026 at 7:13 pm

    In this code you are scanning the string three times for a character:

    if (virtualPath.Contains("?"))
    {
       condition = virtualPath.Substring(virtualPath.IndexOf("?"));
       virtualPath = virtualPath.Substring(0, virtualPath.IndexOf("?"));
    }
    

    Instead, scan it once and use the result three times. Also scan for a char instead of a string:

    int pos = virtualPath.IndexOf('?');
    if (pos != -1) {
       condition = virtualPath.Substring(pos);
       virtualPath = virtualPath.Substring(0, pos);
    }
    

    Here you are doing several replaces with the same replacement:

    virtualPath = virtualPath.ToLower().Replace(",", "-").Replace("%20", "-").Replace("&", "-");
    

    Instead you can use a regular expression to match all of them:

    virtualPath = Regex.Replace(virtualPath.ToLower(), "(,|%20|&)", "-");
    

    (Whether this actually gives better performance has to be tested with some of your actual data. Eventhough it’s less operations, there is some overhead in setting up the regular expresson.)


    You are using a loop to reduce clusters of characters:

    while (virtualPath.Contains("--"))
    {
       virtualPath = virtualPath.Replace("--", "-");
    }
    

    Instead you can use a regular expression to make a single replacement:

    virtualPath = Regex.Replace(virtualPath, "-{2,}", "-");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 310k
  • Answers 310k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My sites use both. The trailing slash indicates something specific… May 13, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer In the specs it says: Whenever the toDataURL() method of… May 13, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer Have you tried using syn match instead of syn region?… May 13, 2026 at 10:14 pm

Related Questions

Im a newbie in javascript and i really aprecciate any ideas of how i
I have a function I've written to convert from a 64-bit integer to a
can anyone help me how to read .doc and .xsl file on linux server
Can anyone help me how to make the UIPickerView displays the first row's value
I just forgot the password. Can anyone help me how to get back the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.