Development Desk

Just another site

Category Archives: Uncategorized

Get Domain Name without any Sub-domain name


you can get domain name without any sub-domain by using below method

public string GetDom(HttpRequest Request)
          var fullDomain = new      Uri(Request.Url.Host.ToLower()).GetComponents(UriComponents.Host, UriFormat.SafeUnescaped);

        if (fullDomain.EndsWith(“.com”))
               return GetHostUrl(fullDomain, 2);
        else if (fullDomain.EndsWith(“”))
               return GetHostUrl(fullDomain, 3);
        return fullDomain;

public string GetHostUrl(string hostUrl, int parameters)
         var domainParts = hostUrl
         .Split(‘.’) // [“test”, “example”, “co”,”uk”]
         .Reverse() // [“uk”,”co”, “example”, “test”]
         .Take(parameters) // [“uk”,”co” “example”]
         .Reverse(); // [“example”, “co”,”uk”]
          var domain = String.Join(“.”, domainParts);
          return domain;

These method can be made more generic.


Regular Expression to check Valid UK Postcode for Upper and Lower case

It is Regular Expression to check valid post code for UK for both Upper and Lowecase

^((?i)([A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]| [ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]))\ ?[0-9][ABD-HJLNP-UW-Z]{2}|

(GIR\ 0AA)|(SAN\ TA1)|(BFPO\ (C\/O\)?[0-9]{1,4})|((ASCN|BBND|[BFS]IQQ|PCRN|STHL|TDCU|TKCA)\ 1ZZ))$



Convert String to GUID in C#

string can be converted to GUID just by

Guid stringToGuid = new Guid(“GUID value in the form of String”);

for example

Guid stringToGuid = new Guid(“91a61ee7-48bb-4371-ad33-72oI67c9b3e”); 

it will give same Guid in return but in the form of GUID


Solution for an Exception in WCF “HTTP could not register URL http://+:8000/EssentialWCF/. Your process does not have access rights to this namespace”

All you just need to do is run your Visual Studio by an Administrator, by right click on visual studio and select “Run as Administrator”

Thank you