asp.net 第五天 html简单的模板

来源:互联网 发布:活动执行方案范文知乎 编辑:程序博客网 时间:2024/06/05 18:09


Login.ashx

==============================================


<%@ WebHandler Language="C#" Class="Login" %>



using System;
using System.Web;


public class Login : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/html";
        
        string username=context.Request["username"];
        string password=context.Request["password"];
        string html = "<html><head></head><body><form action='Login.ashx' method='get'><input type='text' name='username' value='{username}'/><input type='password' name='password' value='{password}'/><input type='submit' value='登陆'></form><p>{msg}</p></body></html>";
        
        if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password))
        {
            //context.Response.Write("<html>");
            //context.Response.Write("<head></head>");
            //context.Response.Write("<body><form action='Login.ashx' method='get'><input type='text' name='username'/><input type='password' name='password'/><input type='submit' value='登陆'></form></body>");
            //context.Response.Write("</html>");
            string code = html.Replace("{username}","");
            code = code.Replace("{password}","");
            code = code.Replace("{msg}","");
            context.Response.Write(code);
        }
        else
        {
            if (username == "admin" && password == "123")
            {
                context.Response.Write("<html><head></head><body>登陆成功</body></html>");




            }
            else
            {
                //context.Response.Write("<html>");
                //context.Response.Write("<head></head>");
                //context.Response.Write("<body><form action='Login.ashx' method='get'><input type='text' name='username' value='"+username+"'/><input type='password' name='password' value='"+password+"'/><input type='submit' value='登陆'><p>用户名或者密码错误</p></form></body>");
                //context.Response.Write("</html>");
                string code = html.Replace("{username}",username);
                code = code.Replace("{password}",password);
                code = code.Replace("{msg}","用户名或者密码错误");
                context.Response.Write(code);
                
                
                
                
                // context.Response.Write("<html><head></head><body>用户名或者密码错误</body></html>");
            
            }
        
        }
        
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }


}
原创粉丝点击