ajax ashx cookie,how to call ashx file using ajax in asp.net
Step: 1 Create the handler and the server side code like the following
using System;
using System.Web;
using System.Linq;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/json";
var processes = System.Diagnostics.Process.GetProcesses();
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
context.Response.Write(serializer.Serialize(processes.Select(p => p.ProcessName)));
}
public bool IsReusable {
get {
return false;
}
}
}
Step 2: Give the necessary permissions for your asp.net process / application pool. In development version you can add the impersonation tag in the web.config as a shortcut.
Step 3:
Use the handler's result from the aspx page via ajax or otherwise. An example is as follows using the jquery library.
CodeFile="Default.aspx.cs" Inherits="_Default" %>
$(function () {
$.get("handler.ashx", function (data) {
$.each(data, function (index, element) {
$("#processes").append($("
").html(element));});
});
});
Hope this helps.