VS调试提示HTTP Status 404 - /caslogin错误,求大神解答

mr_mrl 2016-04-06 01:23:33
全部代码如下:
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;
using System.Net.Security;

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

protected void Page_Load(object sender, EventArgs e)
{
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;

// 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["身份"] = "学生";
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 static bool RemoteCertificateValidate (
Object sender,
X509Certificate certificate,
X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors
)
{
//Return True to force the certificate to be accepted.
return true;
}

}
...全文
503 12 打赏 收藏 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mr_mrl 2016-04-06
  • 打赏
  • 举报
回复
我的网页文件的根目录是thesis原版,其下面也没有caslogin这个文件夹。
wdh123love 2016-04-06
  • 打赏
  • 举报
回复
根目录下找不到"caslogin"文件夹,看一下你是不是以/caslogin为根目录了
mr_mrl 2016-04-06
  • 打赏
  • 举报
回复
恩恩,谢谢大神了,我觉得是我的web.config文件配置的问题,现在网页文件里面的网页都打不开了,都是提示此错误。
fei缘如水 2016-04-06
  • 打赏
  • 举报
回复
引用 8 楼 mr_mrl 的回复:
在呀,我这个是网页文件,里面都是各种网页和代码,大神,要不我加你QQ吧,求大恨帮我把这个问题解决了。
路径不知道写,就把右侧文件夹里的需要打开的页面直接拖到页面上会有个路径 你再贴到转页的地方。。。我也是上班ing,有点空就回复下你,一会说不定就没空了
mr_mrl 2016-04-06
  • 打赏
  • 举报
回复
在呀,我这个是网页文件,里面都是各种网页和代码,大神,要不我加你QQ吧,求大恨帮我把这个问题解决了。
fei缘如水 2016-04-06
  • 打赏
  • 举报
回复
你那文件有在项目里没。。另外是文档还是页面?
mr_mrl 2016-04-06
  • 打赏
  • 举报
回复
我要打开的是E:\毕业设计\thesis原版\caslogin文件
fei缘如水 2016-04-06
  • 打赏
  • 举报
回复
引用 3 楼 mr_mrl 的回复:
怎么看路径?
比如你要链接到X文件夹下的A页面。那路径就是 X\A.aspx这样的地址,你要显示的页面的路径在哪
mr_mrl 2016-04-06
  • 打赏
  • 举报
回复
web.config 文件代码如下: <?xml version="1.0"?> <!-- 办公室: <add name="DTDC" connectionString="Data Source=TDJ-PC\WAKING;Initial Catalog=DegreeThesisDatabase;Integrated Security=True" providerName="System.Data.SqlClient"/> 家里面: <add name="DTDC" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=G:\工程\thesis\App_Data\DegreeThesisDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/> 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="DTDC" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=E:\毕业设计\thesis原版\App_Data\DegreeThesisDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/> </connectionStrings> <system.web> <authentication mode="Forms" > <forms name="casauth" loginUrl="caslogin.aspx" /> </authentication> <authorization> <deny users="?" /> </authorization> <httpRuntime executionTimeout="36000" maxRequestLength="2097151"/> <compilation debug="true" strict="false" explicit="true" targetFramework="4.0"> <assemblies> <add assembly="Office, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/> <add assembly="Microsoft.Office.Interop.Word, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"/> </assemblies> </compilation> <membership> <providers> <clear/> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/> </providers> </membership> <profile> <providers> <clear/> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> </providers> </profile> <roleManager enabled="false"> <providers> <clear/> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/> </providers> </roleManager> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
全栈极简 2016-04-06
  • 打赏
  • 举报
回复
404是路径不对,检查一下路径吧。
fei缘如水 2016-04-06
  • 打赏
  • 举报
回复
404 找不到页面。你看看路径
mr_mrl 2016-04-06
  • 打赏
  • 举报
回复
怎么看路径?

62,270

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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