Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using client.xyz.com in place of www.xyz.com/app/index.asp?clientid=12

Status
Not open for further replies.

LWComputingMVP

IS-IT--Management
Jul 3, 2005
870
US
I have a client with a web site that he needs to allow his clients a more "customized" look and feel. For example, his clients can log in to his site and access their data at
BUT, he wants to give them a more personalized look (in part because these clients will be offering access to their portion of the web site to their clients. So what he wants is some AUTOMATED way to myclientsclientname.myclientssite.com to respond synonymously with
Now my understanding of the technology (using ASP.NET and IIS 6) is that the only way to do this would be to give each client a DNS record and then check the header to see which client's data should be accessed. But is there any other way? Or any way to script the creation of the DNS record? (They don't currently manage their own DNS on their server, but they could).

(I'm asking this on several sites as I need to ensure the broadest possible range of answers - but any answer I get that's not from here I'll post back for your information).
 
Let me start by saying this is the Classic ASP forum and we have a separate forum for ASP.NET here: forum855

Anyway, you can do this with Classic ASP / IIS so the same technique will probably work for your ASP.NET.


This is how you do it....

Assumption: You have a database where a client identifier is associated with a client name. For example you might have a table named "Clients" that contains a column named ClientID and another column named "Name"

Assumption 2: Your web hosting company will allow you to tweak the operation of IIS using the Admin tool.


Think of the 404 File Not Found error that you get when you request a non-existant page. You want to make a custom 404 error page!

In the custom page, you read the HTTP Request header to get the name of the requested client.

In Classic ASP: (VBScript)[tt]
Dim strServerName
Dim iDotPosition
Dim strClientName
strServerName = Request.ServerVariables("SERVER_NAME")
iDotPosition = Instr(strServerName, ".")
If iDotPosition > 1 Then
strClientName = Left(strServerName, (iDotPosition - 1))
End If
[/tt]

Now that you have the requested name, you connect to your database and find the row where the Name column matches the value from the HTTP request. Use the column values from the matching table row to present the "customized" page.

Note: If no match is found then you have an real 404 error so you need to retain the ability to show the 404 including setting the Response Status code to "404 File Not Found"

Note 2: Ideally you can modify your clients table to add a column specifically for the custom URL. This would be cleaner than parsing the SERVER_NAME to take every character before the first dot.


Anyway, once you have this page put together, you use the IIS Admin tool to specifiy the new custom 404 error page for the root of your web site.
 
I thought I posted this in the ASP.NET forum - sorry.

That's an innteresting method and one I actually understand easily. On another site, someone has suggested using Wildcard DNS records.

Using this method, I would expect myclientsclientname.myclientssite.com would simply act as a forwarder to this:

That may suffice, but the wildcard DNS will likely work better - if I can figure it out.

(Any idea how I can move this to the ASP.NET forum?)
 
I would expect myclientsclientname.myclientssite.com would simply act as a forwarder
Yes, forwarding or redirecting the Request would likely give cleaner and more supportable source code than a single page for both the 404 error and the full homepage.

 
You can just wildcard the subdomains (most hosts that offer dns config will let you do this), which will mean that anything.domain.tld will actually be domain.tld - no forwarding, just your server accepting it as a request for the content of domain.tld.

e.g. sheco.domain.tld/showprofile.aspx would show the specific profile for sheco, but would use the same aspx page as for all other users.

You would probably want to create some real subdomains, like api.domain.tld or admin.domain.tld, depending on your needs for your site etc - just make sure they are not allowed as clients names in the dynamic site.

Then as Sheco notes, create database entries for the client ids with what other data you need and read the server name requested/the full domain name - and parse the first bit of it for use as the id.

You shouldn't need a custom 404 for that, however..

If you want to do it with a directory (e.g. rather than subdomain, then you will need to either use the ASP.NET http handlers to intercept the request of the path and rewrite the url ([google]ASP.NET URL rewriting http handler[/google]) or select the appropriate page to execute, or use custom 404's in ASP. Here's a full example of ASP custom url rewriting:
A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top