我用这样的方式调用远程操作WebRequest
:
var site = "http://remoteSite.com/controller/IsolateSite?url=xxx&target=in";
var request = (HttpWebRequest)WebRequest.Create(site);
var response = (HttpWebResponse)request.GetResponse();
if (response.StatusDescription == "OK")
{ /* code */ }
else
{ /* code */ }
在远程操作中,我返回一条消息或null
(如果id
好或不好)。
但是即使动作返回response.StatusDescription
也总是等于。"OK"
null
如何强制将错误作为状态或检索消息(如"Cool."
或"Error."
)?
远程操作示例:
public static string IsolateSite(string url, string target)
{
var serverManager = new ServerManager();
var isHttps = url.Contains("https");
var regex = new Regex("^(http|https)://");
var host = regex.Replace(url, "");
var instance = serverManager.Sites.First(site => site.Bindings.Any(binding => binding.Host == host));
var pool = instance.Applications[0].ApplicationPoolName;
if ((pool.Contains("isolation") && target == "out") || (!pool.Contains("isolation") && target == "in"))
{
return "Error."; //or return null but the status code is OK so useless
}
//etc...
return "Cool.";
}