Home All Groups Group Topic Archive Search About

One application... multiple domains

Author
15 Dec 2005 10:39 PM
Ryan
I am developing an application using ASP.NET 2.0. In this application, I need
to provide customized database-driven interfaces based on the domain name
that the user is accessing the application from. A list of these domains will
be avialable in a data table.

What is the most efficient way to determine which domain the application
should respond for each time a page is requested.

It would seem that executing a SQL query each time a page is requested would
be overkill... is there a better way to do this? I'm assuming there must be,
since applications like dotnetnuke can display different content for multiple
domains...

Thanx

Author
16 Dec 2005 3:06 AM
Chris Love
I would load your domain list into cache, like an array, etc.  You can query
against the cached list which will be very fast.  I do not know how often
your domain list changes, but you can keep it in cache for limited time, or
even setup a SQL Server callback to reset the cache if you are in 2005.  I
have not done this yet, so you are on your own here.

Show quote
"Ryan" wrote:

> I am developing an application using ASP.NET 2.0. In this application, I need
> to provide customized database-driven interfaces based on the domain name
> that the user is accessing the application from. A list of these domains will
> be avialable in a data table.
>
> What is the most efficient way to determine which domain the application
> should respond for each time a page is requested.
>
> It would seem that executing a SQL query each time a page is requested would
> be overkill... is there a better way to do this? I'm assuming there must be,
> since applications like dotnetnuke can display different content for multiple
> domains...
>
> Thanx
Author
16 Dec 2005 3:21 AM
Joshua Flanagan
How are you using the word "domain"? Do you mean Windows Domain - as in
a Domain Controller? In this case, you should be able to get the domain
name which is prefixed on the user's name (Page.User.Identity.Name) if
you have Windows Authentication enabled on the website (and anonymous
access disabled).

You then write logic to show different interfaces based on that domain
string.

You could even write a custom RoleProvider which uses the person's
domain name to determine their role. That way you could take advantage
of the role-based security built into the new ASP.NET 2.0 sitemap and
Navigation controls. That would allow you to declaratively decide which
navigation links will be displayed to each domain. For more info on role
based site navigation, check out this article:
http://weblogs.asp.net/scottgu/archive/2005/11/20/431019.aspx

For help writing a custom RoleProvider, you can download my Visual
Studio template from here:
http://flimflan.com/blog/ASPNETRoleProviderVisualStudioTemplate.aspx

Just fill in the code for GetRolesForUser() to return the user's domain
name. Something like this:

public string[] GetRolesForUser(string username){
   int domainPos = username.IndexOf('\');
   string domain = String.Empty;
   if (domainPos > 0) {
     domain = username.SubString(0, domainPos);
   }
   return new string[] { domain };
}


Joshua Flanagan
http://flimflan.com/blog
Author
16 Dec 2005 2:21 PM
Ryan
Well.... by "domain", I mean domain name, which I don't believe is the same
as a domain controller (right?). This is an application designed for public
(anonymous) users, and will not be using Windows Authentication.

Ryan

Show quote
"Joshua Flanagan" wrote:

> How are you using the word "domain"? Do you mean Windows Domain - as in
> a Domain Controller? In this case, you should be able to get the domain
> name which is prefixed on the user's name (Page.User.Identity.Name) if
> you have Windows Authentication enabled on the website (and anonymous
> access disabled).
>
> You then write logic to show different interfaces based on that domain
> string.
>
> You could even write a custom RoleProvider which uses the person's
> domain name to determine their role. That way you could take advantage
> of the role-based security built into the new ASP.NET 2.0 sitemap and
> Navigation controls. That would allow you to declaratively decide which
> navigation links will be displayed to each domain. For more info on role
> based site navigation, check out this article:
> http://weblogs.asp.net/scottgu/archive/2005/11/20/431019.aspx
>
> For help writing a custom RoleProvider, you can download my Visual
> Studio template from here:
> http://flimflan.com/blog/ASPNETRoleProviderVisualStudioTemplate.aspx
>
> Just fill in the code for GetRolesForUser() to return the user's domain
> name. Something like this:
>
> public string[] GetRolesForUser(string username){
>    int domainPos = username.IndexOf('\');
>    string domain = String.Empty;
>    if (domainPos > 0) {
>      domain = username.SubString(0, domainPos);
>    }
>    return new string[] { domain };
> }
>
>
> Joshua Flanagan
> http://flimflan.com/blog
>
Author
17 Dec 2005 1:40 AM
Joshua Flanagan
Yes, a domain name is different from a domain controller. And an
internet domain name is very different than the Windows domain name that
I was thinking of.

If you want to know the internet DNS host name that the user entered in
their address bar, try:

Request.Url.Host

AddThis Social Bookmark Button