1,配置web文件
<?xml version="1.0"?>
<configuration>
<appSettings>
<!--单点登录-->
<add key="ServiceURL" value="http://"/>
<add key="CASHost" value="http://"/>
<add key="CASError" value="http://"/>
<add key="OutUrl" value="http://"/>
<!--<add key="casLoginURL" value=""/>-->
</appSettings>
<!--配置上传文件限制M-->
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime executionTimeout="6000" maxRequestLength="409600" requestValidationMode="2.0" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/>
</system.web>
</configuration>
2,获取路径地址传值,获取参数值
public void HaveId()
{
//string strNetID = null, strTicket = "", validateUrl = "";
//string CASHost = "http://";
//string mainUrl1 = Page.Request.QueryString["ReturnUrl"];
//string ServiceURL = "http://localhost:50904/Login.aspx?ReturnUrl=" + mainUrl1;
string strNetID = null, strTicket = "", validateUrl = "";
string CASHost = ConfigurationManager.AppSettings["CASHost"];//proxyValidate/
string mainUrl1 = Page.Request.QueryString["ReturnUrl"];
string ServiceURL = ConfigurationManager.AppSettings["ServiceURL"] + "?ReturnUrl=" + mainUrl1;
strTicket = Page.Request.QueryString["ticket"];
if (strTicket == null || strTicket.Length == 0)
{
string redir = CASHost + "login?service=" + ServiceURL;
Page.Response.Redirect(redir);
}
//============== read ticket and request validation ==================
validateUrl = CASHost + "serviceValidate?ticket=" + strTicket + "&service=" + ServiceURL;
System.IO.StreamReader Reader = new System.IO.StreamReader(new System.Net.WebClient().OpenRead(validateUrl));
string resp = Reader.ReadToEnd(); //return(resp);
System.Xml.NameTable nt = new System.Xml.NameTable();
System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(nt);
System.Xml.XmlParserContext context = new System.Xml.XmlParserContext(null, nsmgr, null, System.Xml.XmlSpace.None);
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(resp, System.Xml.XmlNodeType.Element, context);
while (reader.Read())
{
if (reader.IsStartElement())
{
string tag = reader.LocalName;
if (tag == "user") strNetID = reader.ReadString();
}
}
reader.Close();
SaveInfo(strNetID);
}
3,根据参数值,判断是否存在改账号信息进行登录