the. ashx file used to write Web handler . ashx files is similar to an. aspx file that enables you to invoke the HttpHandler class, eliminating the control parsing and page processing of normal. aspx pages. In fact, it's a mixed file with HTML and C #.
The. ashx file is suitable for producing data formats that are processed by the browser and do not require postback processing. For example, to generate dynamic pictures, dynamic text and other content. Very much needs to be used in this way. This document provides a simple demo of calling the Ashx file and pasting the source code of the important file.
The following is the source code in the Login.ashx file in the demo:
public class Login:ihttphandler {public void ProcessRequest (HttpContext context) {context. Response.ContentType = "Application/json"; Get method gets the data passed//string username = context. request.querystring["username"]; String Password = context. request.querystring["Password"]; The Post method gets the data passed in string username = context. request.form["username"]; String Password = context. request.form["Password"]; String message = NULL; if (string. IsNullOrEmpty (username)) {message = "user name cannot be empty"; Context. Response.Write ("{\" success\ ": False,\" message\ ": \" + message + "\"} ");//This JSON format is important, otherwise it will run jquery's error function context . Response.End (); } if (string. IsNullOrEmpty (password)) {message = "Password cannot be empty"; Context. Response.Write ("{\" success\ ": False,\" message\ ": \" "+ Message +" \ "}"); Context. Response.End (); } if (!string. IsNullOrEmpty (username) &&!string. IsNullOrEmpty (password)) {if (username. ToUpper () = = "ADMIN" && password = = "123") {message = "login successful"; Context. Response.Write ("{\" success\ ": True,\" message\ ": \" "+ Message +" \ "}"); } else {message = "User name or password error"; Context. Response.Write ("{\" success\ ": False,\" message\ ": \" "+ Message +" \ "}"); }} context. Response.End (); } public bool IsReusable {get {return false; } }}
The following is the source code in HTML:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
jquery Interview ashx file Demo sample