asp.net页面整理

页面模板

把html内容在一般处理程序里添加

  public void ProcessRequest(HttpContext context) { 
  context.Response.ContentType = "text/html";
context.Response.Write("<html>");
context.Response.Write("<head></head>"); //\="login.ashx"
context.Response.Write(@"<body><form action=‘login.ashx‘>用户名:<input type=‘text‘ name=‘username‘ /><br />
     密码 <input type=‘text‘name=‘pwd‘ /><br /><input type=‘submit‘ value=‘登录‘ /></form></body>");    
        context.Response.Write("</html>");  }

把输出的html 代码写成字符串

  public void ProcessRequest(HttpContext context) {
   context.Response.ContentType = "text/html";
   string username = context.Request["username"]; 
   string pwd = context.Request["pwd"]; 
   string html="<html>"+"<head></head>"+"<body><form action=‘login.ashx‘>" +  
                "<font color=‘red‘> 用户名:<font><input type=‘text‘ name=‘username‘ value=‘{username}‘/><br/>" +
               "<font color=‘red‘> 密码:<font><input type=‘text‘ name=‘pwd‘ value=‘{pwd}‘/><br/>" +
               "<input type=‘submit‘ value=‘登录‘ /><p>{msg}</p>"+
                "</form></body>"+"<html>"; 
   if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(pwd)) 
      {  context.Response.Write("</html>");       
          string code = html.Replace("{username}", "");   
          code=  code.Replace("{passord}","");         
        context.Response.Write(code);
     }
     else            
       {    if (username == "admin" && pwd == "123")    
             { context.Response.Redirect("DOM.html"); }    
             else                
             { string code = html.Replace("{username}", username);   
                code=  code.Replace("{passord}", pwd);         
              code = code.Replace("{msg}", "你输入的账号和密码不对");   
                  context.Response.Write(code);                                         //context.Response.Write("你输入的账号和密码不对");                 }                              
        }                       
}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。