I call a remote action with a WebRequest
like that:
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 */ }
In the remote action, I return a message or null
(if id
is good or not).
But response.StatusDescription
is always equal to "OK"
even if the action returns null
.
How can I force an error as status or retrieve a message (like "Cool."
or "Error."
)?
The remote action sample :
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.";
}