欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

單點登錄解決方案

系統(tǒng) 2124 0

網(wǎng)上看到很多單點登錄的原理和實例,講的像廣告一樣。哎,我看了好幾天還是看不明白。但是項目需要這個功能,于是,我自己做了一個。發(fā)布出來,希望像我一樣的需求的人能早些解決問題。

思路:使用第三方認(rèn)證。那么就要用到跨域訪問(就是變量要在不同ip地址下實現(xiàn)訪問),大白話說,就是網(wǎng)絡(luò)訪問。我不會Socket,就用Remoting吧!(Application不可以,因為它不能跨主機(jī))

看代碼:

1,建類庫StatusService,在它里面建類LoginList

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace StatusService
{
??? public class LoginList : MarshalByRefObject, IList
??? {
??????? private object[] _contents = new object[8];
??????? private int _count;

??????? public LoginList()
??????? {
??????????? _count = 0;
??????? }

??????? // IList Members
??????? public int Add(object value)
??????? {
??????????? if (_count < _contents.Length)
??????????? {
??????????????? _contents[_count] = value;
??????????????? _count++;

??????????????? return (_count - 1);
??????????? }
??????????? else
??????????? {
??????????????? return -1;
??????????? }
??????? }

??????? public void Clear()
??????? {
??????????? _count = 0;
??????? }

??????? public bool Contains(object value)
??????? {
??????????? bool inList = false;
??????????? for (int i = 0; i < Count; i++)
??????????? {
??????????????? if (_contents[i] == value)
??????????????? {
??????????????????? inList = true;
??????????????????? break;
??????????????? }
??????????? }
??????????? return inList;
??????? }

??????? public int IndexOf(object value)
??????? {
??????????? int itemIndex = -1;
??????????? for (int i = 0; i < Count; i++)
??????????? {
??????????????? if (_contents[i] == value)
??????????????? {
??????????????????? itemIndex = i;
??????????????????? break;
??????????????? }
??????????? }
??????????? return itemIndex;
??????? }

??????? public void Insert(int index, object value)
??????? {
??????????? if ((_count + 1 <= _contents.Length) && (index < Count) && (index >= 0))
??????????? {
??????????????? _count++;

??????????????? for (int i = Count - 1; i > index; i--)
??????????????? {
??????????????????? _contents[i] = _contents[i - 1];
??????????????? }
??????????????? _contents[index] = value;
??????????? }
??????? }

??????? public bool IsFixedSize
??????? {
??????????? get
??????????? {
??????????????? return true;
??????????? }
??????? }

??????? public bool IsReadOnly
??????? {
??????????? get
??????????? {
??????????????? return false;
??????????? }
??????? }

??????? public void Remove(object value)
??????? {
??????????? RemoveAt(IndexOf(value));
??????? }

??????? public void RemoveAt(int index)
??????? {
??????????? if ((index >= 0) && (index < Count))
??????????? {
??????????????? for (int i = index; i < Count - 1; i++)
??????????????? {
??????????????????? _contents[i] = _contents[i + 1];
??????????????? }
??????????????? _count--;
??????????? }
??????? }

??????? public object this[int index]
??????? {
??????????? get
??????????? {
??????????????? return _contents[index];
??????????? }
??????????? set
??????????? {
??????????????? _contents[index] = value;
??????????? }
??????? }

??????? // ICollection Members

??????? public void CopyTo(Array array, int index)
??????? {
??????????? int j = index;
??????????? for (int i = 0; i < Count; i++)
??????????? {
??????????????? array.SetValue(_contents[i], j);
??????????????? j++;
??????????? }
??????? }

??????? public int Count
??????? {
??????????? get
??????????? {
??????????????? return _count;
??????????? }
??????? }

??????? public bool IsSynchronized
??????? {
??????????? get
??????????? {
??????????????? return false;
??????????? }
??????? }

??????? // Return the current instance since the underlying store is not
??????? // publicly available.
??????? public object SyncRoot
??????? {
??????????? get
??????????? {
??????????????? return this;
??????????? }
??????? }

??????? // IEnumerable Members

??????? public IEnumerator GetEnumerator()
??????? {
??????????? // Refer to the IEnumerator documentation for an example of
??????????? // implementing an enumerator.
??????????? throw new Exception("The method or operation is not implemented.");
??????? }

??????? public void PrintContents()
??????? {
??????????? Console.WriteLine("List has a capacity of {0} and currently has {1} elements.", _contents.Length, _count);
??????????? Console.Write("List contents:");
??????????? for (int i = 0; i < Count; i++)
??????????? {
??????????????? Console.Write(" {0}", _contents[i]);
??????????? }
??????????? Console.WriteLine();
??????? }

??? }
}

?2,建一個控制臺SSOService

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;

namespace SSOService
{
??? class MyServer
??? {
??????? [STAThread]
??????? static void Main(string[] args)
??????? {
??????????? RemotingConfiguration.Configure("SSOService.exe.config");
??????????? Console.ReadLine();
??????? }

??? }
}

配置文件是:

<configuration>
? <system.runtime.remoting>
??? <application name="SSOService">
????? <service>
??????? <wellknown type="StatusService.LoginList,StatusService" objectUri="StatusService.LoginList"
??????????? mode="Singleton" />
????? </service>
????? <channels>
??????? <channel ref="tcp" port="9999"/>
????? </channels>
??? </application>
? </system.runtime.remoting>
</configuration>

3,網(wǎng)站S1文件:

Default.aspx

Login.aspx

Web.config

(1)Default.aspx內(nèi)容就是:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html xmlns=" http://www.w3.org/1999/xhtml ">
<head runat="server">
??? <title>S2</title>
</head>
<body>
??? <form id="form1" runat="server">
??? <div>
??? S2登陸成功!
??? </div>
??? </form>
</body>
</html>

實際使用按照需求自由調(diào)整。

(2)Login.aspx

前臺是:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html xmlns=" http://www.w3.org/1999/xhtml ">
<head runat="server">
??? <title>S2</title>
</head>
<body>
??? <form id="form1" runat="server">
??? <div style="line-height:30px;">
??? <div>s2登陸界面</div>
??? 用戶:<asp:TextBox id="user" Text="abc" runat="server"></asp:TextBox><br />
??? 密碼:<asp:TextBox ID="pwd" Text="123" runat="server"></asp:TextBox><br />
??? <asp:Button ID="Button1" Text="登陸" OnClick="Button1_OnClick" runat="server" />
??? </div>
??? </form>
</body>
</html>

后臺是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
??? StatusService.LoginList ls = (StatusService.LoginList)Activator.GetObject(typeof(StatusService.LoginList), System.Configuration.ConfigurationSettings.AppSettings["ServiceURL"]);
??? protected void Page_Load(object sender, EventArgs e)
??? {
??????? Response.Write("記錄條數(shù)是:" + ls.Count.ToString() + "<br/>");
??????? for (int i = 0; i < ls.Count; i++)
??????? {
??????????? //Response.Write(ls[i] + "<br/>");
??????????? if (ls[i].ToString().Trim()=="abc")
??????????? {
??????????????? Response.Redirect("Default.aspx");
??????????? }

??????? }
??? }

??? protected void Button1_OnClick(object sender, EventArgs e)
??? {
??????? ls.Add("abc");
??????? Response.Redirect("Default.aspx");
??? }
}

(3)Web.config

<?xml version="1.0"?>
<configuration>
?<appSettings>
??<add key="ServiceURL" value="tcp://localhost:9999/StatusService.LoginList"/>
?</appSettings>
?<system.web>
??<compilation debug="true" targetFramework="4.0"/>
?</system.web>
</configuration>

4,再建一個S2,和S1一樣。

5,運(yùn)行時要設(shè)置多項目運(yùn)行,并且是最先運(yùn)行SSOService。

完畢!

上敘是在vs2010上測試的。絕對簡單實用,沒有廣告!不實就砸我吧,我認(rèn)!有好的建議希望多賜教!謝謝了!

單點登錄解決方案


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久草在线国产视频 | 奇米视频在线 | 国产在线观看福利 | 精品国产精品三级精品av网址 | 99国精产品一区二区三区A片 | 激情五月综合 | 九色av | 日韩国产欧美视频 | 国产免费观看一区 | 九九热色 | 亚洲欧美日韩中文字幕在线不卡 | 欧美在线观看a | 国产在线观看中文字幕 | 四季久久免费一区二区三区四区 | 色影影院 | 亚州精品天堂中文字幕 | www.亚洲黄色| 久久久久久久99精品免费观看 | 欧美日韩一区二区三区在线观看 | 欧美系列在线播放 | 亚洲一区二区三区中文字幕 | 91精品国产综合久久久密闭 | 免费看av的网址 | 人人爽人人爽 | 天天碰天天操 | 国产午夜精品一区二区三区嫩草 | 亚洲国产中文字幕在线观看 | 日韩精品久久一区二区三区 | 久久婷五月 | 成年网站免费观看 | 日产一一到六区麻豆 | 一级做a爰片性色毛片中国 日本黄色免费片 | 久久综合亚洲一区二区三区 | 免费高清成人 | 久久精品国产99国产精品澳门 | 国产亚洲欧美在线 | 欧美国产日韩在线观看 | 555夜色666夜色精品站 | 综合二区 | 久久成人在线视频 | 欧美精品一区二区三区蜜桃视频 |