C# .NET - Single Sign on using ASP.Net (C#.Net)

Asked By Partha Sarathy
04-Dec-09 11:31 PM

Hi !

            I need a Sample Application in Single Sign on using ASP.Net (C#.Net) using Cookies or SQL Data Base (or) any other Examples would be better.....

Thanks & Regards

 

 

Examples  Examples

05-Dec-09 12:23 AM

You can impement SSO at coockies and domain level. You will need Forms Authentication Ticket and Cookies to make susccessful SSO like below.

//call SetAuthCookie method to log in. A forms authentication cookie is created.
// Domain name in the cookie defaults to the subdomain where the application resides
FormsAuthentication.SetAuthCookie(txtUserName.Text, false);

//modify the Domain attribute of the cookie to the second level domain
System.Web.HttpCookie MyCookie =
       System.Web.Security.FormsAuthentication.GetAuthCookie(User.Identity.Name.ToString(),
                                                             false);
MyCookie.Domain = “mysite.com”;//the second level domain name
Response.AppendCookie(MyCookie);

In ASP .NET configuration file (web.config) there is an element inside <system.web> element named <machineKey> which Configures keys to use for encryption and decryption of Forms authentication cookie data and view-state data and for verification of out-of-process session state identification. In the web.config of both projects, change the authentication node to this:

<authentication mode="Forms">
<forms name="SampleAuth"
loginUrl="/TestWebApp2/Test.aspx"
slidingExpiration="true">
</forms>
</authentication>

Change the loginUrl to be that of your login page. Then change the
authorization node in the web.config to be this:

<authorization>
<deny users="?" />
</authorization>

In your login page, when you've authenticated the user, do this:

System.Web.Security.FormsAuthentication.RedirectFr omLoginPage("Andy", true);

Now, in your other applications (Webapp2 for example), you can get at the
username ("Andy" in this case), by using:

System.Web.HttpContext.Current.User.Identity.Name

I'd recommend reading up on forms authentication and security.

You can find complete example at http://www.codeproject.com/KB/aspnet/SingleSignon.aspx and http://aspalliance.com/1545_Understanding_Single_SignOn_in_ASPNET_20.all

Also read http://blah.winsmarts.com/2006/05/19/aspnet-20-implementing-single-sign-on-sso-with-membership-api.aspx and http://bytes.com/topic/asp-net/answers/343134-single-sign-transfer-credential-between-webapps

Single Sign on using ASP.NET  Single Sign on using ASP.NET

05-Dec-09 09:08 AM
Building your own framework to implement single sign-on is complex. 

An efficient & time-tested way to implement a single sign-on solution is to use Passport authentication or OpenId

For info on implementing Passport Single Sign-in for ASP.NET pages, check this article - http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=16

Excerpts on OpenId from Wikipedia - http://en.wikipedia.org/wiki/OpenID
OpenID is a shared identity service, which allows Internet users to log on to many different web sites using a single digital identity, single sign-on, eliminating the need for a different user name and password for each site. OpenID is a decentralized, free and open standard that lets users control the amount of personal information they provide.

OpenID is increasingly gaining adoption among large sites, with organizations like AOL, BBC, Google,IBM, Microsoft,MySpace, Orange, VeriSign, Yandex and Yahoo! acting as providers.In addition, OpenID can be used with Windows CardSpace.

To implement OpenID for your ASP.NET website, check these links:
ASP.NET drop-in control to enable OpenID logins for your site - http://blog.nerdbank.net/2007/01/aspnet-drop-in-control-to-enable-openid.html
Integrate OpenId Authentication with ASP.NET Membership, Roles, and Profile - http://www.eggheadcafe.com/tutorials/aspnet/4b3c7c9b-fe80-4e6e-a34e-0e9efed5c575/integrate-openid-authenti.aspx
C# OpenID library - http://code.google.com/p/dotnetopenid/

Refer the article by Peter Bromberg  Refer the article by Peter Bromberg

05-Dec-09 12:16 PM
that talks about "Single Sign-On with DIGEST, BASIC and LDA" The article can be found here.

Create New Account
help
FormsAuthentication .NET Framework I have a few questions regarding the FormsAuthentication object. 1. What's the difference between the SetAuthCookie & GetAuthCookie methods of the FormsAuthentication object? 2. How do you create a cookie that stores itself in the Temporary Internet the user's computer? 3. What exactly is FormsAuthenticationTicket? How is it different from the FormsAuthentication cookie? ASP.NET Discussions FormsAuthenticationTicket (1) FormsAuthentication (1) SetAuthCookie (1) GetAuthCookie (1) GregoryBeamer (1) Beamer (1) Bcdcfd425f07 (1) Cookie (1) This might help: http
Question about cookie protection and FormsAuthentication.Encrypt .NET Framework I'm a little unclear on when exactly I would need to use FormsAuthentication.Encrypt. If I have the cookie protection in the web.config set to All (i be encrypted and tamper-proof even if I don't encrypt the authentication ticket using FormsAuthentication.Encrypt? What do I gain by also using FormsAuthentication.Encrypt in addition to the the web.config setting? Or is this more of a double-check than anything else? ASP.NET Security Discussions ASP.NET (1) FormsAuthentication (1) FormsAuthenticationTicket (1) RedirectFromLoginPage (1) SetAuthCookie (1) GetAuthCookie (1) Encrypt (1) You only need to call Encrypt if you are manually creating the FormsAuthenticationTicket and adding it to the cookies collection. If you are using FormsAuthentication.SetAuthCookie or RedirectFromLoginPage this is done automatically for you (according to config settings). - -- -- Dominick Baier
the submit button click on Login page after validation? BTW I have not used the 'GetAuthcookie', 'SetAuthCookie' or 'RedirectFromLoginPage' methods. I am posting the code inside the submit button click on the New FormsAuthenticationTicket(1, txtuserid.Text, DateTime.Now, DateTime.Now.AddMinutes(30), chkRemember.Checked, "14062010") cookiestr = FormsAuthentication.Encrypt(tkt) ck = New HttpCookie(FormsAuthentication.FormsCookieName, cookiestr) If chkRemember.Checked Then ck.Expires = tkt.Expiration End If ck.Path = FormsAuthentication.FormsCookiePath Response.Cookies.Add(ck) Dim strRedirect As String = "" strRedirect = Request("ReturnUrl") If strRedirect Is Logon_Click( object sender, EventArgs e) { if ((UserEmail.Text = = "jchen@contoso.com" ) && (UserPass.Text = = "37Yj*99Ps" )) { FormsAuthentication.RedirectFromLoginPage (UserEmail.Text, Persist.Checked); } else { Msg.Text = "Invalid credentials. Please try again." ; } } < / script> <html EventArgs e) { Welcome.Text = "Hello, " + Context.User.Identity.Name; } void Signout_Click( object sender, EventArgs e) { FormsAuthentication.SignOut(); Response.Redirect( "Logon.aspx" ); } < / script> <body> <h3> Using Forms Authentication< / h3> <asp:Label ID You Can Correct Your Code. . . / / I Hope This Will Helpful For You. . . You can use FormsAuthentication.RedirectFromLoginPage(UserName, True) or FormsAuthentication.SetAuthCookie(UserName, true) Response.Redirect("AuthorizedPage.aspx") Where variable UserName
Forms Authentication, Identities and Roles from a Database FormsAuthentication, Identities and Role - based Security with a database By Peter A. Bromberg, Ph.D. Printer successful understanding and implementation of Forms - based authentication are first - to become familiar with the FormsAuthentication class, its members and properties, and second - to learn how to implement it programmatically with use the above code, lets take a quick pass through a condensed version of the FormsAuthentication class: FormsAuthentication Members Public Constructors FormsAuthentication Constructor Initializes a new instance of the FormsAuthentication class. Public Properties FormsCookieName Returns the configured cookie name used for the current application. FormsCookiePath given a FormsAuthenticationTicket. Equals (inherited from Object ) Overloaded. Determines whether two Object instances are equal. GetAuthCookie Overloaded. Creates an authentication cookie for a given user name. GetHashCode (inherited from Object ) Serves this routine produces a hash password suitable for storing in a configuration file. Initialize Initializes FormsAuthentication by reading the configuration and getting the cookie values and encryption keys for the given