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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:59:30+00:00 2026-06-01T23:59:30+00:00

Firstly, this seems like something that should have been asked before, but I cannot

  • 0

Firstly, this seems like something that should have been asked before, but I cannot find anything that answers my question.

A basic overview of my task is to render an anchor link on a web page which is based on a user defined web address. As the address is user defined this could be in any format, for example:

  • http://www.example.com
  • https://www.example.com
  • http://www.example.com
  • example.com

What I need to do with this value is to set it as the href property of an anchor tag. Now, the problem is that (in Chrome at least) only the first two examples will work due to the fact they are recognised as absolute URL paths. The last two examples will redirect to the same domain (i.e. treated as relative paths)

So the ultimate question is: What is the best way to format these values to ensure a consistent absolute path is used? I could check for http/https and add it if missing, but I was hoping there might be an out of the box .Net class that would be more reliable.

In addition, as this is a user defined value, it could be complete junk anyway so a function to validate the URL would be a nice bonus too.

  • 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-01T23:59:31+00:00Added an answer on June 1, 2026 at 11:59 pm

    We ran into this problem a few months back, and needed a consistent way of ensuring the URLs were absolute. We also wanted a way of removing http(s):// for displaying the URL on the web page.

    I came up with this function:

    public static string FormatUrl(string Url, bool IncludeHttp = null)
    {
    
        Url = Url.ToLower();
    
        switch (IncludeHttp) {
            case true:
                if (!(Url.StartsWith("http://") || Url.StartsWith("https://")))
                    Url = "http://" + Url;
                break;
            case false:
                if (Url.StartsWith("http://"))
                    Url = Url.Remove(0, "http://".Length);
                if (Url.StartsWith("https://"))
                    Url = Url.Remove(0, "https://".Length);
                break;
        }
    
        return Url;
    
    }
    

    I know you’re after an “out of the box” library, but this may be of some help.

    I think the problem with an “out of the box” solution would be that the function won’t know whether the URL should be http:// or https://. With my function I’ve made an assumption that its going to be http://, but for some URLs you need https://. If Microsoft were to build something like this into the framework, it would be buggy from the start.

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

Sidebar

Related Questions

Firstly, I've asked this question elsewhere , but meta.stackoverflow.com seems to think that asking
Firstly, this seems like (from ContourPlot) a fairly straightforward maximization problem, why is FindMaximum
Firstly, This might seem like a long question. I don't think it is... The
Firstly: I am totally a newbie for this kind of work. I have a
Firstly, I do not have any malicious intent out of this question. I would
I have been asked to setup VisualSVN for Visual Studio 2008. Due to firewall
Firstly, let me set out what I'd like to do. Assume I have three
I have a string like this: Tickets order: № 123123123. CED-MSW-RPG-MOW-CEK PODYLOVA/ALEMR 555 423578932
Firstly Id like to say thanks to everyone who has helped me this week
I have searched on strings, lists, append etc. but can't seem to handle this.

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.