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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:16:09+00:00 2026-05-27T11:16:09+00:00

The method UrlHelper.GenerateUrl() is located in System.Web.Mvc.UrlHelper I need a different implementation that would

  • 0

The method UrlHelper.GenerateUrl() is located in System.Web.Mvc.UrlHelper

I need a different implementation that would affect everything from Url.Action() to Html.BeginForm().

This is the current .NET implementation:

    [SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "As the return value will used only for rendering, string return value is more appropriate.")]
    public static string GenerateUrl(string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues) { 
        string url = GenerateUrl(routeName, actionName, controllerName, routeValues, routeCollection, requestContext, includeImplicitMvcValues);

        if (url != null) {
            if (!String.IsNullOrEmpty(fragment)) { 
                url = url + "#" + fragment;
            } 

            if (!String.IsNullOrEmpty(protocol) || !String.IsNullOrEmpty(hostName)) {
                Uri requestUrl = requestContext.HttpContext.Request.Url; 
                protocol = (!String.IsNullOrEmpty(protocol)) ? protocol : Uri.UriSchemeHttp;
                hostName = (!String.IsNullOrEmpty(hostName)) ? hostName : requestUrl.Host;

                string port = String.Empty; 
                string requestProtocol = requestUrl.Scheme;

                if (String.Equals(protocol, requestProtocol, StringComparison.OrdinalIgnoreCase)) { 
                    port = requestUrl.IsDefaultPort ? String.Empty : (":" + Convert.ToString(requestUrl.Port, CultureInfo.InvariantCulture));
                } 

                url = protocol + Uri.SchemeDelimiter + hostName + port + url;
            }
        } 

        return url; 
    } 

I know that its possible to override static methods using delegates, but that won’t allow all of method calls to the same method from different classes use my implementation instead of the default one.

  • 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-27T11:16:10+00:00Added an answer on May 27, 2026 at 11:16 am

    What you are asking for is not possible. If you want to modify the output of Url and Html helpers you could either write custom ones or simply change your route definitions. Helpers use those route definitions when generating urls. You could even write custom routes if you have some very specific requirements about how the urls should look like throughout your entire application.

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

Sidebar

Related Questions

I'm looking for an alternative in ASP.NET 2.0 to : ASP.NET 3.5's System.Web.Mvc.UrlHelper.Content method.
Which method would you recommend to pass data from a child view back to
I created a simple extension method for the ASP.NET MVC UrlHelper. It takes no
I'm writing a helper method for ASP.NET MVC and I need to call Url.Content
I would like to use the Mvc UrlHelper in conjunction with JQuery Templates. Example
I have standart MVC web project that register routes in global.asax. My MVC project
why defined extension method with UrlHelper don't added in Url. EXTENSIONMETHOD when i want
I'm trying to add an extension method to my MVC 2 project without success
I'm trying to write a test for an UrlHelper extensionmethod that is used like
Method swizzling works great for instance methods. Now, I need to swizzle a class

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.