2

I am totally new to URL Rewriting and WildCard Subdomain management.

My requirement is that I have a gridview in my ASP.Net 3.5 WebApp from where a hyperlinks navigate url property is dynamically generating the following url.

http://businessbazaar.in/BusinessBazaarAspx/Details.aspx?cid=1&name=Steel_Bird_Fabricators

Note : here _ denotes the white space between the words.

Now what I want is that when a user click on the url ,the browser will rewrite the url to

http://steelbirdfabricators.businessbazaar.in

I want it to achieve this via some dll or web.config. I don't want it on IIS as setting, Is this possible? Then please tell me how? It will be highly appreciated.

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • 1
    What you describe is not how URL rewriting works. The browser does not rewrite URLs the web server does. E.g. the server receives businessbazaar.in/Steel_Bird_Fabricators/ and it get's rewritten to: businessbazaar.in/BusinessBazaarAspx/Details.aspx?cid=1&name=Steel_Bird_Fabricators. The firs thing you need to do is get the gridview to generate the URLs that you want the user to see. – Ben Robinson Aug 23 '11 at 16:09
  • 1
    Writing the URL in the way you want is fairly trivial - however managing the all sub-domains dynamically, and handling the requests when the user follows the rewritten URLs is where things get tricky - is that what you're really looking for help with? – Zhaph - Ben Duguid Aug 23 '11 at 16:11
  • Is this possible to achieve??? –  Aug 23 '11 at 16:12
  • @Zhaph - I want to know if I can convert the original url (http://businessbazaar.in/BusinessBazaarAspx/Details.aspx?cid=1&name=Steel_Bird_Fabricators) to new (http://steelbirdfabricators.businessbazaar.in) one. That is, instead of gridviews url browser will display the subdomain one. –  Aug 23 '11 at 16:15
  • 1
    @See-Sharp What you describe is not actually URL rewriting, but i don't really think what you describe is what you want. With URL rewriting you can have the user enter http://steelbirdfabricators.businessbazaar.in in the browser (or click a link to it) and it serves up http://businessbazaar.in/BusinessBazaarAspx/Details.aspx?cid=1&name=Steel_Bird_Fabricators without redirecting the browser, i.e. the url stays as http://steelbirdfabricators.businessbazaar.in. Is that what you are after? – Ben Robinson Aug 23 '11 at 16:18
  • 1
    @See-Sharp, what you are describing is the opposite of URL rewriting. you can achieve what you describe by putting code in Details.aspx that redirects the browser to the relevant subdomain, it is then up to you to server up the correct content on that subdomain. – Ben Robinson Aug 23 '11 at 16:19
  • @ben : you can achieve what you describe by putting c.. Sorry i did,nt get you –  Aug 23 '11 at 16:21
  • @See-Sharp i posted half a message by mistake, read the comment again. – Ben Robinson Aug 23 '11 at 16:23
  • 1
    means i need to create a subdomain on my host. What If i have 100 users registered a day. If i am right then I will have to create individual subdomains manually. But I want this part automatically managed by application. –  Aug 23 '11 at 16:26
  • Whenever a user will register at my site, he will have a subdomain ready to server. This what I want. –  Aug 23 '11 at 16:27

1 Answers1

2

I'm assuming that somewhere in your gridview you have something like this:

<asp:TemplateField HeaderText="Url">
  <ItemTemplate>
    <asp:HyperLink ID="HyperLink1" runat="server"
                   Text='<%# Bind("CategoryName") %>'
         NavigateUrl='http://businessbazaar.in/BusinessBazaarAspx/Details.aspx?cid=1
                      &name=<%# Eval("CategoryName") %>' ></asp:HyperLink>
  </ItemTemplate>
</asp:TemplateField>

If you were to change that to something like

<asp:TemplateField HeaderText="Url">
  <ItemTemplate>
    <asp:HyperLink ID="HyperLink1" runat="server"
                   Text='<%# Bind("CategoryName") %>'
         NavigateUrl='http://<%# Eval("CategoryName") %>.businessbazaar.in/' >
    </asp:HyperLink>
  </ItemTemplate>
</asp:TemplateField>

Then that would solve the requested issue.

However this isn't going to deal with the implicit question - which is "How do I dynamically handle subdomains" - which is where your pain is probably going to start:

For this to work in IIS, you'll need a wildcard DNS entry set up, and then a dedicated IP address for the sites in IIS that you can map all these requests on to (it appears that IIS doesn't support wildcard host header entries).

You'll then need to set up something like the UrlRewrite IIS module or similar to handle the requests and work out what it actually needs to send to your application to get the correct information back to the user.

As a point of note, most SEO people will recommend against sub domains for permanent areas of your site as they carry less weight than pages/folders beneath the main domain. So you'd be better off taking the easier option of URLs such as: http://businessbazaar.in/steel-bird-fabricators (Note also the more SEO friendly use of hyphens to separate the words rather than underscores or mashingthemalltogther).

Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117