提示:“System.Net.ServicePointManager.CertificatePolicy”已过时,错误,求大神帮忙看看。

mr_mrl 2016-03-30 02:43:40
我要做网页的CAS单点登录的集成,按原文件编写如下,但是提示错误,求大神帮忙改正。代码如下:

using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.Adapters;
using System.IO;
using System.Xml;
using System.Net;
using System.Security.Cryptography.X509Certificates;

public partial class login : System.Web.UI.Page
{
// Local specific CAS host
private const string CASHOST = "http://192.168.191.1:38080/cas/";

protected void Page_Load(object sender, EventArgs e)
{
System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();

// Look for the "ticket=" after the "?" in the URL
string tkt = Request.QueryString["ticket"];

// This page is the CAS service=, but discard any query string residue
string service = Request.Url.GetLeftPart(UriPartial.Path);

// First time through there is no ticket=, so redirect to CAS login
if (tkt == null || tkt.Length == 0)
{
string redir = CASHOST + "login?" +
"service=" + service;
Response.Redirect(redir);
return;
}

// Second time (back from CAS) there is a ticket= to validate
string validateurl = CASHOST + "serviceValidate?" +
"ticket=" + tkt + "&" +
"service=" + service;
StreamReader Reader = new StreamReader(new WebClient().OpenRead(validateurl));
string resp = Reader.ReadToEnd();
// I like to have the text in memory for debugging rather than parsing the stream

// Some boilerplate to set up the parse.
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;



// A very dumb use of XML. Just scan for the "user". If it isn't there, its an error.
while (reader.Read())
{
if (reader.IsStartElement())
{
string tag = reader.LocalName;
if (tag == "user")
netid = reader.ReadString();




}
}
// if you want to parse the proxy chain, just add the logic above
reader.Close();
// If there was a problem, leave the message on the screen. Otherwise, return to original page.
if (netid == null)
{
Label1.Text = "CAS returned to this application, but then refused to validate your identity.";
}
else
{
if (!Page.IsPostBack)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DTDC"].ConnectionString);
myConnection.Open();
string cmd_text = "SELECT * from 学生 where 标准学号='" + netid + "'";
string cmd_text01="SELECT * from 教师 where 标准工号='" + netid + "'";
SqlDataReader datar;
SqlCommand mycommand = new SqlCommand(cmd_text, myConnection);
SqlCommand mycommand01 = new SqlCommand(cmd_text01, myConnection);
datar = mycommand.ExecuteReader();
while (datar.Read())
{
if (datar != null) {
Session.Add("身份", null);
Session["身份"] = "学生";
Response.Redirect ("~/index_student.aspx");}
else {
datar =mycommand01.ExecuteReader();
if (datar != null)
{
Session["身份"] = "教师";
Response.Redirect("~/index_teacher.aspx");
}
else {
Response.Redirect("~/index.aspx");
}

}


}

myConnection.Close();

}


Response.Write("连接成功");
}
}
}

public class MyPolicy : ICertificatePolicy
{
public bool CheckValidationResult(
ServicePoint srvPoint
, X509Certificate certificate
, WebRequest request
, int certificateProblem)
{

//Return True to force the certificate to be accepted.
return true;

} // end CheckValidationResult
} // class MyPolicy
...全文
407 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mr_mrl 2016-03-31
  • 打赏
  • 举报
回复
好了,谢谢大神们,太感谢了。
Go 旅城通票 2016-03-31
  • 打赏
  • 举报
回复
引用 5 楼 mr_mrl 的回复:
大神,添加了还是提示错误。
你的回调函数作用域有问题啊,你放到MyPolicy类下面了,login那个类访问不到 = new System.Net.Security.RemoteCertificateValid(MyPlolicy.RemoteCertificateValid)
mr_mrl 2016-03-31
  • 打赏
  • 举报
回复
大神,添加了还是提示错误。


Go 旅城通票 2016-03-31
  • 打赏
  • 举报
回复
引用 7 楼 mr_mrl 的回复:
好了,谢谢大神们,太感谢了。
那就把你发的帖子接了吧,你应该发到asp.net去,这个是asp,不是同一个东西
Go 旅城通票 2016-03-30
  • 打赏
  • 举报
回复
要导入2个名字空间,要不你调用的方法了

using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
slwsss 2016-03-30
  • 打赏
  • 举报
回复
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((a, b, c, d) => { ..... return false; });
mr_mrl 2016-03-30
  • 打赏
  • 举报
回复
大神,但是按照你给的网址改过之后提示:错误 1 “System.Net.Security.RemoteCertificateValidationCallback”是“类型”,但此处被当做“变量”来使用 。请问这是怎么回事呀?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧