ASP.NET ----ashx一般处理程序

asp.net中的一般处理程序,文件后缀为ashx。

代码示例:

    /// <summary>
    /// login 的摘要说明
    /// </summary>
    public class login : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            loginRequest(context);
        }

        private void loginRequest(HttpContext context)
        {
            string struser = context.Request.QueryString["user"].ToString();
            string strpwd = Tem.Utils.MD5Service.GetMD5(context.Request.QueryString["pwd"].ToString());

            int i = Tem.BLL.th_LoginUserManager.GetLoginUsers(struser, strpwd);

            context.Response.ContentType = "text/html";
            context.Response.Write(i.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

 

IIS添加对ashx文件的支持

网站目录下,打开“处理程序映射”,如下图:

指定本地目录

 

url访问,实例:http://localhost:90/login.ashx?user=&pwd=

 

Winform访问示例代码,如下:

                string url = "http://localhost:90/login.ashx" + "?user=" + this.txtuser.Text + "&pwd=" + this.txtpwd.Text;
                WebClient webclient = new WebClient();
                string str = webclient.DownloadString(url);

 

你可能感兴趣的:(asp.net)