从不同的 asp.net 页面调用 asp.net 页面(ashx 处理程序)

发布于 2024-09-08 19:32:24 字数 340 浏览 7 评论 0原文

我在 asp.net 中有一个管理页面,用于将数据添加到数据库中。该数据库可作为 JSON 字符串提供给外部网站,但是,由于数据量很大,外部网站会在本地缓存该数据。

我希望能够 ping 外部网站,让他们知道数据已更改,以便他们可以引用其缓存。我想我可以设置一个 ASHX 处理程序,该处理程序接收一个参数,告诉他们哪些数据已更改,这样他们就可以删除该数据并刷新它。

我唯一不确定的部分是从我的管理页面调用此外部页面的最佳方式。我是否只执行常规 WebRequest 并丢弃结果?或者当您不需要响应时是否有更简单的方法从代码调用页面?

基本上我只是想“ping”这个页面,所以它知道它需要刷新。

谢谢!

I have a admin page in asp.net that adds data to a database. This database is available as a JSON string to external websites, however, since it's a lot of data, the external websites cache this data locally.

I want to be able to ping the external websites to let them know the data has changed so they can referesh their cache. I figure I can setup an ASHX handler that receives a parameter telling them what data has changed, so they can both delete that data and refresh it.

The only part I'm not sure about is the best way to call this external page from my admin page. Do I just do a regular WebRequest and discard the result? or is there a simpler way to call a page from code when you don't need the response?

Basically I just want to "ping" this page, so it knows it needs to refresh.

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╭ゆ眷念 2024-09-15 19:32:24

如果只想调用远程页面,可以使用WebRequest类。
http://msdn.microsoft.com/en-us/library/debx8sh9。 aspx

WebRequest request = WebRequest.Create("http://my.domain.ext/page.ashx");
using(WebResponse response = request.GetResponse()) {
  response.Close();
}

如果你想做更高级的事情,网络服务会更合适。

If you just want to call the remote page, you can use the WebRequest class.
http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

WebRequest request = WebRequest.Create("http://my.domain.ext/page.ashx");
using(WebResponse response = request.GetResponse()) {
  response.Close();
}

If you want to do more advanced stuff a webservice would be more appropriate.

北方的韩爷 2024-09-15 19:32:24

您可以在数据库中设置一个标志。这将把这变成一个更简单的任务。

如果没有替代方案,您可以使用 WebClient 类:

using (var wc = new WebClient()) 
{
    wc.DownloadString(address);
}

You could have a flag set up in the database. That would turn this into a much simpler task.

If no alternative exists you can use the WebClient class:

using (var wc = new WebClient()) 
{
    wc.DownloadString(address);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文