The ashx file is similar to the. aspx file. You can use it to call the HttpHandler class. The following describes how jquery accesses the ashx file. The ashx file is used to write web handler .. The ashx file is similar to the. aspx file. It can be used to call the HttpHandler class, which removes the need for normal. aspx page control parsing and page processing. It is actually a hybrid file with HTML and C.
The. ashx file is suitable for generating data formats that are not processed by the browser, such as dynamic images and text. Many require this processing method. This document provides a simple Demo for calling the ashx file and posts the source code of the key file.
The source code in the Login. ashx file in the Demo is as follows:
Public class Login: IHttpHandler {public void ProcessRequest (HttpContext context) {context. response. contentType = "application/json"; // GET method to obtain transmitted data // string username = context. request. queryString ["username"]; // string password = context. request. queryString ["password"]; // obtain the passed data in the POST mode. string username = context. request. form ["username"]; string password = context. request. form ["password"]; string Message = null; if (string. isNullOrEmpty (username) {message = "username cannot be blank"; context. response. write ("{\" success \ ": false, \" message \ ": \" "+ message +" \ "}"); // This JSON format is very important, otherwise, the error function context of jquery will be executed. response. end ();} if (string. isNullOrEmpty (password) {message = "the password cannot be blank"; context. response. write ("{\" success \ ": false, \" message \ ": \" "+ message +" \ "}"); context. response. end () ;}if (! String. IsNullOrEmpty (username )&&! String. isNullOrEmpty (password) {if (username. toUpper () = "ADMIN" & password = "123") {message = "Logon successful"; context. response. write ("{\" success \ ": true, \" message \ ": \" "+ message + "\"}");} else {message = "incorrect user name or password"; context. response. write ("{\" success \ ": false, \" message \ ": \" "+ message +" \ "}") ;}} context. response. end () ;}public bool IsReusable {get {return false ;}}}
The source code in html is as follows:
Jsquery access the ashx File