小弟刚学asp 遇到一些脑残级的问题,求大神
问题:小弟新建的一个空的asp 网站,然后又只建了 html 和ashx 两个界面,为什么登录后
html 代码不解析了如下是登录后的界面 :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>登陆程序</title>
</head>
<body>
<form action="SimgleLogin.ashx" method="post" >
<input type ="text" name="txtName" />
<input type ="text" name="txtPwd" />
<input type ="submit" value="登陆" />
</form>
</body>
</html>
我登陆成功了----
源码是:
ashx 里的代码:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string modePath = context.Server.MapPath("HTMLPage.htm");
string htmlSendBack= System.IO.File.ReadAllText(modePath);
context.Response.ContentType = "text/plain";
context.Response.Write(htmlSendBack);
if (!string.IsNullOrEmpty(context.Request.Form["txtName"]))
{
if(context.Request.Form["txtName"]=="skyming"&&context.Request.Form["txtPwd"]=="111")
context.Response.Write("我登陆成功了----");
}
else
{
context.Response.Write("我登陆失败了----");
}
}
public bool IsReusable {
get {
return false;
}
}
}
html 里面的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>登陆程序</title>
</head>
<body>
<form action="SimgleLogin.ashx" method="post" >
<input type ="text" name="txtName" />
<input type ="text" name="txtPwd" />
<input type ="submit" value="登陆" />
</form>
</body>
</html>
[解决办法]
context.Response.ContentType = "text/plain";改成context.Response.ContentType = "text/html"试试呢