1

How to check what is wrong in domain URL in C#

I want to updated domain URL when invalid domain enter.

Input Put of Domain:          OutPut Like

1)http:/localhost:1234/------>http://localhost:1234/
2)http://localhost:1234------>http://localhost:1234/
3)http:localhost:1234/------->http://localhost:1234/
4)http:localhost:1234-------->http://localhost:1234/
5)localhost:1234/------------>http://localhost:1234/
6)localhost:1234------------->http://localhost:1234/

Also above all test cases with HTTPS

May be need add more test cases.

I have code of nopCommerece for warning but it's use only current store .

How I develop a code for enter domain is valid or not and return valid domain.

Kalpesh Boghara
  • 302
  • 2
  • 18

2 Answers2

1

My understanding of the question is you want to take in a given URL and output a correction. At the very minumum you are looking for the string "localhost:1234". You could use a regular expression to check for the existence of this string. If true, output "http://localhost:1234/"

The regular express is "/localhost:1234/g" and can be found here: http://regexr.com/3e2n8

To check this regular expression in C# you will code:

Regex regex = new Regex(@"/localhost:1234/g");
    Match match = regex.Match("http:/localhost:1234/"); // your given string
    if (match.Success)
    {
        // your given string contains localhost:1234
    }
tmutton
  • 1,069
  • 6
  • 18
  • 42
  • If I have http:/www.test.com then? As mention in my question domain url so not use only in local – Kalpesh Boghara Aug 23 '16 at 05:00
  • Hello @KalpeshBoghara - your original question does not include that. You will need to update your original question. Please state your question clearly. – tmutton Aug 23 '16 at 08:58
-3

In any domain name the following are important:

www..com:

portnumber is 80 by default

but still, to check and get the Exception, use this URL,

Best way to determine if a domain name would be a valid in a "hosts" file?

Community
  • 1
  • 1
Angad
  • 62
  • 4