using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Net;
using System.IO;
namespace ssotest
{
?/// <summary>
?/// login 的摘要說明。
?/// </summary>
?public class login : System.Web.UI.Page
?{
??protected System.Web.UI.WebControls.Label Label1;
??private const string CASHOST = "https://localhost:8443/cas/";
??
??private void Page_Load(object sender, System.EventArgs e)
??{
???// 在此處放置用戶代碼以初始化頁面
???String tkt=Request.QueryString["ticket"];
???string service = Request.Url.GetLeftPart(UriPartial.Path);
???if (tkt == null || tkt.Length == 0)
???{
????string redir = CASHOST + "login?" +???????????????? "service=" + service;
????Response.Redirect(redir);
????return ;
???}
???string validateurl = CASHOST + "serviceValidate?" +
????"ticket=" + tkt + "&"+
????"service=" + service;
???//Response.Write(validateurl);
???System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
???StreamReader Reader = new StreamReader( new WebClient().OpenRead(validateurl));
???string resp = Reader.ReadToEnd();
???NameTable nt = new NameTable();
???XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
???XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
???XmlTextReader reader = new XmlTextReader(resp, XmlNodeType.Element, context);
???string netid = null;
???while (reader.Read())
???{
????if (reader.IsStartElement())
????{
????? string tag = reader.LocalName;
????? if (tag=="user")????????????????
?????? netid = reader.ReadString();????????????????
????}
???}
??? reader.Close();
???if (netid == null)
???{
????Label1.Text = "CAS returned to this application, but then refused to validate your identity.";????????
???}
???else
???{
????? Label1.Text = "Welcome " + netid;?
???? // FormsAuthentication.RedirectFromLoginPage(netid, false);
???}
??}
??public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
??{
???public TrustAllCertificatePolicy()
???{}
?
???public bool CheckValidationResult(ServicePoint sp,
????System.Security.Cryptography.X509Certificates.X509Certificate cert,
????WebRequest req, int problem)
???{
????return true;
???}
??}
??#region Web 窗體設計器生成的代碼
??override protected void OnInit(EventArgs e)
??{
???//
???// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
???//
???InitializeComponent();
???base.OnInit(e);
??}
??
??/// <summary>
??/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
??/// 此方法的內容。
??/// </summary>
??private void InitializeComponent()
??{???
???this.Load += new System.EventHandler(this.Page_Load);
??}
??#endregion
?}
}
posted on 2006-11-09 11:51
robbin163 閱讀(1383)
評論(0) 編輯 收藏