如何调用的HttpHandler从cs文件asp.net [英] How to call HttpHandler from .cs file asp.net

查看:92
本文介绍了如何调用的HttpHandler从cs文件asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个HTTP处理程序来回回我Jquery的Ajax调用。这是工作的罚款jQuery的调用如下

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",
    contentType: "text/plain",
    data: {
        CustMobile: a,
        CustName: b,
        CustEmail: c
    },
    contentType: "application/json; charset=utf-8",
    success: function (data) {
        $("#loading").hide();
    },
    error: function () {
        $("#loading").hide();
    }
});

现在我的问题是,我这可拨打name.ashx处理程序通过我的code后面。我使用asp.net使用C#。我知道,它可以通过回复于()编写脚本的整个部分被调用。答也注册页面方法的脚本。

但有什么办法由我可以发送请求处理程序,并使用C#返回从处理程序的响应。

Now my problem is this can I call the name.ashx handler through my code behind. I am using asp.net with C#. I know that it can be called by Response.write("") writing the whole script part. Ans also Register Script of page method.
But Is there any way by which I can send request to handler and get back response from the handler using c#.

感谢。

推荐答案

您还可以从code任何HTTP资源利用背后的HttpWebRequest (System.Net命名空间)

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

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

您需要一个绝对路径,但是你可以从HttpContext的让你的域或服务器URL如果你不想硬code域

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

  • MSDN - HttpWebRequest Class

这篇关于如何调用的HttpHandler从cs文件asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆