4

I would like to allow my users to have their own dedicated URL, for example if my URL is www.XYZ.com, my users will have www.NAME.XYZ.com OR www.XYZ.com/NAME.

At the moment you can see their page by going to www.XYZcom/Member.aspx?userID="012345"

Now I would like to somehow map the URL to the currect system.

I have no idea whatwhat I need to do, I have seem many websites that have done this, so I hope that it would be possible for me to do the same in ASP .net.

Thank you in Advance. Cheers

3 Answers 3

2

If your domain name DNS record is pointing to the IP address of the site, you should be able to access the site using anything.XYZ.com.

When you create a users account, you need to asign them a unique subdomain name and then detect this when users get to the site using their domain name (see the code below)

/// <summary>
        /// Gets the Current SubDomain
        /// </summary>
        /// <returns></returns>
        public static string GetSubDomain()
        {
            string subDomain = String.Empty;

            if (HttpContext.Current.Request.Url.HostNameType == UriHostNameType.Dns)
            {
                subDomain = Regex.Replace(HttpContext.Current.Request.Url.Host, "((.*)(\\..*){2})|(.*)", "$2");
            }

            if (subDomain.Length == 0)
            {
                subDomain = "www";
            }

            return subDomain;
        }
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much, its much appreciated. I will use this technique in my website.
I think a key issue will be - how do you create all those subdomains? (by hand?)
Alex, I am searching the web to find out how to do that :) do you have any idea how to do this ?
This is inherently complex, if not impossible using IIS. Which is why I brought it up (the other side to your question). I wanted to do the same but couldn't find a sufficient answer on how to do this with IIS (while this is somewhat easy to do with Apache)
See my answer for a way to do this.
2

If you need to do this with IIS and ASP.NET i think this method will work:

  1. Use a DNS-host that will allow you do register wildcard-domains. That way you can register ****.xyz.com*** to point to your server.
  2. Now comes the part you may not like; for this to work on IIS you will need to set up your site as "default web site". That way, all requests will come to your site, even if the subdomain is not in the list of headers for that site. This will not work if your site is hosted on a shared webhost.
  3. Use Marks method to detect what domain the user has typed in.

3 Comments

Espo, Have you done this before ? Is it easy to find a Hosting company that offer such a service ?
Wonder if this is possible with GoDaddy or any other large domain provider?
I do not think it's easy to find a provider that will do this for you on a shared host. You will however be able to do this if you find a hosting provider that will give you a dedicated server. (It will cost you more that a normal hosting package).
2

HI, You can use URL Rewriting in your application. Using this feature simply you can redirect URLs like : www.XYZ.com/012345 to the page: www.XYZ.com/Member.aspx?userID="012345". You can download URL Rewriter sample from microsoft website. after you add URLRewriter.dll reference to your website. After you add the following lines to your web.config file in your website:

  <RewriterConfig>
    <Rules>
      <RewriterRule>
        <LookFor>~/([a-z]+)-([a-z]+)\.html</LookFor>
        <SendTo>~/Contact.aspx?FirstName=$1&amp;LastName=$2</SendTo>
      </RewriterRule>
    </Rules>
  </RewriterConfig>

The above code redirects(using URLRewriter library) URLs like www.mydomain.com/name-family.html to www.mydomain.com/Contact.aspx?FirstName=name&LastName=family you can change this to suite your needs. Content of LookFor tag are some regular expression for my case, you should write your own regular expression.

You can view the article and download the source code here at MSDN.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.