开发者

Call an asp.net page (ashx handler) from a different asp.net page

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!


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.


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜