asp.net簡單實現單點登入(SSO)的方法_實用技巧

來源:互聯網
上載者:User

本文執行個體講述了asp.net簡單實現單點登入(SSO)的方法。分享給大家供大家參考,具體如下:

單點登入(Single Sign On , 簡稱 SSO )是目前比較流行的服務於企業業務整合的解決方案之一, SSO 使得在多個應用系統中,使用者只需要登入一次就可以訪問所有相互信任的應用系統

CAS(Central Authentication Service)是一款不錯的針對 Web 應用程式的單點登入架構(耶魯大學開發)主要用於Java Php 有興趣大家可以研究下..

下面是一個簡單實現單點登入的方法:

public void SingleUserLogin(string userName){  //定義索引值  string key=userName;  string value=Convert.ToString(Cache[key]);  if(value==null||value==string.Empty){   //定義Cache到期時間   TimeSpan span=new TimeSpan(0,0,HttpContext.Current.Session.Timeout,0,0);    //第一次登陸的時候插入一個使用者相關的cache值,    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){    //重複登陸    Response.Write("<mce:script type="text/javascript"><!--    alert('您的帳號已經登陸!');window.location='login.aspx';    // --></mce:script>");  }  else{  //取消當前的session會話    Session.Abandon();  }}

在Web Config 配置 表單模式

<authentication mode="Forms">//mode值是Forms為定義成表單驗證  <forms loginUrl="Mananger/Login.aspx" name=".ASPXAUTH">//使用者未登陸就先訪問Mananger/Login.aspx頁面 </forms></authentication><authorization> <deny users="?"/></authorization>

希望本文所述對大家asp.net程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.