allen
专注于java ee技术,包括struts,jsf,webwork,spring,hibernate,ibatis
posts - 7,  comments - 9,  trackbacks - 0

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 阅读(1375) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜