c#实现网站监控查看是否正常示例
代码如下:
public void monitorweb(model.serviceinfo mserverinfo)
{
var surl = mserverinfo.serviceconfig;
var mloginfo = new model.loginfo { serviceid = mserverinfo.serviceid };
try
{
var mwebrequest = (httpwebrequest)webrequest.create(surl);
var mwebresponse = (httpwebresponse)mwebrequest.getresponse();
if (mwebresponse.statuscode == httpstatuscode.ok)
{
mloginfo.status = "1";
mloginfo.remark = "";
mserverinfo.errorcou = 0;
}
else
{
mloginfo.status = "0";
mloginfo.remark = mwebresponse.statusdescription;
mserverinfo.errorcou = mserverinfo.errorcou + 1;
}
mwebresponse.close();
}
catch (exception ex)
{
mloginfo.status = "0";
mloginfo.remark = ex.message;
mserverinfo.errorcou = mserverinfo.errorcou + 1;
}
dal.dbop.updatestate(mserverinfo, mloginfo);
}
最重要部份
var mwebrequest = (httpwebrequest)webrequest.create(surl);
var mwebresponse = (httpwebresponse)mwebrequest.getresponse();
if (mwebresponse.statuscode == httpstatuscode.ok)
上一篇: c# split分隔字符串使用方法
下一篇: asp文本文件操作
推荐阅读