How to call HttpHandler from .cs file asp.net

前端 未结 2 1149
死守一世寂寞
死守一世寂寞 2020-12-31 17:44

I have created a http handler fro my Jquery ajax call. which is working fine the jquery call is mentioned below

 $.ajax({
    url: \"Services/name.ashx\",
           


        
2条回答
  •  庸人自扰
    2020-12-31 18:23

    You can call any http resource from code behind using HttpWebRequest (System.Net namespace)

    Sample

    HttpWebRequest request = (HttpWebRequest) WebRequest.Create("/Services/name.ashx?CustMobile=ValueOfA&CustName=ValueOfB&CustEmail=ValueOfC");
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    

    You need an absolute path but you can get your domain or server url from the HttpContext if you dont want to hardcode the domain

    More Information

    • MSDN - HttpWebRequest Class

提交回复
热议问题