A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李后量 中级黑马   /  2012-9-17 13:01  /  1535 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 李后量 于 2012-9-17 22:14 编辑

在视频学习的ASP.NET初级部分讲一般处理程序的第一个网页小程序:简单的登录,代码也很简单:
  1. public void ProcessRequest (HttpContext context) {
  2.         
  3.         string modelPath = context.Server.MapPath("Login.html");
  4.         string htmlSend = System.IO.File.ReadAllText(modelPath);
  5.         context.Response.ContentType = "text/plain";
  6.         context.Response.Write(htmlSend);
  7.     }
复制代码
在视频里老师写完代码后直接右键然后“在浏览器中查看”就可以在浏览器中看到效果了,但我做了同样的工作却看到了不一样的结果:


刷新页面两次后就正常了,如下图(必须是刷新两次才行),通过在浏览器中输入网址的方式访问的话也是这样。

当点击登录按钮后,又变成第一个图里面那样了……
这又是什么原因呢?刚开始学习ASP.NET就这样………………

评分

参与人数 1技术分 +2 收起 理由
郑文 + 2

查看全部评分

3 个回复

倒序浏览
context.Response.ContentType = "text/plain";//修改为context.Response.ContentType = "text/html";试试看吧!
回复 使用道具 举报
许庭洲 发表于 2012-9-17 13:36
context.Response.ContentType = "text/plain";//修改为context.Response.ContentType = "text/html";试试 ...

这个我试了,运行时能正常显示页面,但是如果在服务器端添加判断语句后,再点击提交按钮却没有任何反应
判断代码如下:
  1.     public void ProcessRequest (HttpContext context) {
  2.         
  3.         string modelPath = context.Server.MapPath("Login.html");
  4.         string htmlSend = System.IO.File.ReadAllText(modelPath);
  5.         context.Response.ContentType = "text/html";
  6.         context.Response.Write(htmlSend);
  7.         if (!string.IsNullOrEmpty(context.Request.Form["txtName"]))
  8.         {
  9.             if (context.Request.Form["txtName"] == "admin" && context.Request.Form["txtPwd"] == "123")
  10.             {
  11.                 context.Response.Write("登录成功~~~~~~~~");
  12.             }
  13.             else
  14.             {
  15.                 context.Response.Write("登录失败…………");
  16.             }
  17.         }
  18.     }
复制代码
回复 使用道具 举报
context.Request.Form["txtName"] 这里面txtName 应该是<input type="text" name="txtName" />
还有测试的时候一定要记着清除浏览器缓存。我就因为这个缓存搞了半天短点才取出了context.Request.Form["txtName"]里面的值。忘记清除缓存了。

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马