您的位置:首页 > 编程语言 > ASP

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

2014-10-13 10:22 330 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: