2
votes

I am trying to create a website with subdomains in asp.net mvc. But I am not sure how to do this. When setting up this new solution in visual studio is it best to have a different project for each subdomain or have one project? There are obviously some immediate advantages to this such as publishing updates to one subdomain without touching the others. Here is the specification:

1)I have many applications , each have their own subdomain, e.g. App1, App2, App3. The user will login through the Main domain with login page, and this authentication will be passed down to the applications.

2) I need the domain to authenticate the user and pass the authentication to the subdomain. The subdomain will only allow access to authenticated users. ASP.NET allows the authentication to be passed to subdomains. What I need to know is how to set the projects so that the subdomian knows that the authentication is being passed this way.

3) I've decided to go down the subdomain route.

http://App1.domain.com/ http://App12.domain.com/

4)I'm also thinking about reusable code. Is there any way to share masterpage,usercontrols etc over the three different subdomains?

2

2 Answers

2
votes

Separate web applications and in the web.config of each set the domain property to the top level domain:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" domain="domain.com" />
</authentication>

This way when a user authenticates on one of the applications, the authentication cookie will contain the domain property and it will be sent along to other applications in this domain and sub-domains and the user will be automatically authenticated on the other applications as well.

1
votes

Thought about a similar situation a few days ago. I found two options for doing the "on the fly subdomain registration"

  1. A subdomain registration tooks no time when root domain is registered!
  2. Rewrite the URL

In case 1 I'd forward *.mydomain.com to the webserver (IIS) in that case and use the IIS Administration API to redirect myuser.mydomain.com to the physical path such as www.mydomain.com/myuser/

In case 2 I'd simply rewrite www.mydomain.com/myuser/* to myuser.mydomain.com/*

Authentication should not be the problem, I would use the a Filter or something like that.