欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c#实现网站监控查看是否正常示例

程序员文章站 2024-02-24 18:00:10
代码如下: 复制代码 代码如下:public void monitorweb(model.serviceinfo mserverinfo)   &n...

代码如下:

复制代码 代码如下:

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)