我所做的就是将这个问题的评论和我自己的一些想法结合起来,在下面提出这个答案。保存为HTML
XML文档(我们的Web服务器不允许XML传输):
<?xml version="1.0" encoding="utf-8"?>
<appstatus>
<online status="true" message="online"/>
</appstatus>
然后,我有以下的代码从上面看,并用它来查看应用程序是否应该关闭或不是:
string testURL = "";
try
{
// Probe for the update server.
// If the update server cannot be reached, an exception will be thrown by the GetResponse method.
#if !DEBUG
testURL = ApplicationDeployment.CurrentDeployment.UpdateLocation.ToString() + "online.html";
#else
testURL = "http://testserver/appname/online.html";
#endif
HttpWebRequest webRequest = WebRequest.Create(testURL) as HttpWebRequest;
webRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse webResponse = webRequest.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
XmlDocument xmlDom = new XmlDocument();
xmlDom.Load(reader);
if (xmlDom["usdwatcherstatus"]["online"].Attributes["status"].Value.ToString() != "true")
{
MessageBox.Show(xmlDom["usdwatcherstatus"]["online"].Attributes["message"].Value.ToString());
this.Close();
return;
}
}
catch (WebException ex)
{
// handle the exception
MessageBox.Show("I either count not get to the website " + testURL + ", or this application has been taken offline. Please try again later, or contact the help desk.");
}
注意我找到了一篇关于移动URL的文章(这不正是我想要的),但它确实有一些关于如何获取发布和更新URL的源代码,我现在可以在我的应用程序中使用它。 http://robindotnet.wordpress.com/2010/01/17/how-to-move-a-clickonce-deployment/ – John 2010-08-05 16:46:45