asp.net simple implementation of single sign-on (SSO) Method _ Practical skills

Source: Internet
Author: User
Tags httpcontext

The example in this article describes the asp.net simple implementation of single sign-on (SSO) method. Share to everyone for your reference, specific as follows:

Single sign-on (Sign on, SSO) is one of the more popular solutions for enterprise business integration, and SSO enables users to access all trusted applications with only one login at a time in multiple application systems

CAS (central authentication Service) is a good single sign-on framework for WEB applications (developed by Yale University) that is mainly used in Java PHP and you can study it.

Here's a simple way to implement a single sign-on:

public void Singleuserlogin (string userName) {
  //define key value
  string key=username;
  String value=convert.tostring (Cache[key]);
  if (value==null| | Value==string. Empty) {
   //define cache Expiration Time
   TimeSpan span=new TimeSpan (0,0,httpcontext.current.session.timeout,0,0);   Insert a user-related Cache value on the first landing,
    HttpContext.Current.Cache.Insert (Key,key,null,datetime.maxvalue,span, System.web.caching.cacheitempriority.notremovable,null);
    session["UserName"]=username;
    Response.Redirect ("main.aspx");
  }
  else if (Cache[key). ToString () ==key) {
    //Repeat login   Response.Write ("<mce:script type= text/javascript" ><!--   alert (' Your account has landed! '); window.location= ' login.aspx ';   --></mce:script> ");
  }
  else{
  //Cancel current session Sessions
    Session.Abandon ();
  }
   

Configure form mode in Web Config

<authentication mode= the "forms" >//mode value is forms for defining form validation
  <forms loginurl= "mananger/login.aspx". Aspxauth ">//users visit mananger/login.aspx page
 </forms>
</authentication>
< without landing authorization>
 <deny users= "?" />
</authorization>

I hope this article will help you to ASP.net program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.