如何查看我的应用运行的平台,AWS EC2实例,Azure角色实例和非云系统?现在我这样做:
if(isAzure())
{
//run in Azure role instance
}
else if(isAWS())
{
//run in AWS EC2 instance
}
else
{
//run in the non-cloud system
}
//checked whether it runs in AWS EC2 instance or not.
bool isAWS()
{
string url = "http://instance-data";
try
{
WebRequest req = WebRequest.Create(url);
req.GetResponse();
return true;
}
catch
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我的应用程序在非云系统中运行时,我遇到了一个问题,例如本地Windows系统.执行isAWS()方法时速度非常慢.代码'req.GetResponse()'需要很长时间.所以我想知道如何处理它?请帮我!提前致谢.