Suppose you have a C# web application which need to run on a internal (inside network) and external (DMZ) web servers. These two application talks to the same database. The internal application need single sign on (SSO) and the external application is form authentication. Now in Visual studio you have one project for both these applications. Depending on the web.config’s configurations the application either do SSO or form authentication.
For SSO the web.config settings are,
<authentication mode="Windows"></authentication>
For form the web.config settings are,
<authentication mode="Forms">
<forms name="LegalAidLogin" loginUrl="~/login.aspx" defaultUrl="~/default.aspx" timeout="30" protection="All" enableCrossAppRedirects="true">
</forms>
</authentication>
Now, when you in login page which you have to need to check the authentication mode on page load, use the code below,
// Load web.config
System.Xml.XmlDocument config = new System.Xml.XmlDocument();
config.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
System.Xml.XmlNode node = config.SelectSingleNode(”//configuration/system.web/authentication”);
// Check the login mode for forgot your password
if (node.Attributes[“mode”].Value == “Forms”)
{}
If you are already login in and you need to check the authentication mode use code below,
if (HttpContext.Current.User.Identity.AuthenticationType != “Forms”)
{}
Leave a Reply