Asp.Net Subdomains Single sign on

Single sign-on
 (SSO) is a property of access control of multiple related, but independent software systems. With this property a user logs in once and gains access to all systems without being prompted to log in again at each of them.

Assuming you have a multiple subdomains and you want the user to log in in one of them and stay logged in even after moving from one subdomain to another.

As we All know subdomains in the IIS can have different sites and different application pool. By default moving from one site/application to another the authentication is lost.

Ofc you can work your own registration/log-in mechanism and work it out through all the subdomains of your portal. By why bother with all this since provided you with the Membership controls, we will only mention a couple of those controls in this post but not in details since it’s not the main topic of this post.

Log in Control:

<asp:Login ID=”LoginUser” runat=”server” ></asp:Login>

Change Password control:

<asp:ChangePassword ID=”ChangeUserPassword” runat=”server”></asp:ChangePassword>

Registration control:

<asp:CreateUserWizard ID=”RegisterUser” runat=”server”></asp:CreateUserWizard>

C# Code behind and Membership Provider

You can always create you own form and still use the membership provider,

To log in from code behind you can use the following code

FormsAuthentication.SetAuthCookie(Username, false /* createPersistentCookie */);

To log-out from code behind you can use the following code


SSO Single Sign on:

Now for the main reason of our article, Single Sign on. It’s fairly easy, all you have to do is add the following configuration line in the web.config of every site. This will only work if you are using the membership provider or

<authentication mode=”Forms”>
<forms name=”AnyNameSSO” loginUrl=”login.aspx” timeout=”524160″ defaultUrl=”/” domain=”” protection=”All” />

Name: You can Choose any name here, preferably put the same name in all the web.config.

LoginURL: Your log in page URL.

Timeout: The time the user stay logged in.

Domain: Your root domain name.

If you have any questions drop us a comment below, Happy Programming.


Leave a Reply