简体   繁体   English

以编程方式检查IIS7启动画面

[英]Programmatically check for IIS7 splash screen

I have a ASP.Net 3.5 Web app (C#) where I need to programmatically check to see if another one of our sites (that isn't ASP.Net) is up and running. 我有一个ASP.Net 3.5 Web应用程序(C#),我需要以编程方式检查我们的另一个站点(不是ASP.Net)是否启动并运行。 Currently, I have a method with the following code which checks for a StatusCode of 200. The issue I'm running into is that the IIS7 splash page that comes up returns a status code of 200, and I don't see anything else within the response object that would allow me to verify the page we are expecting actually displays. 目前,我有一个方法,使用以下代码检查StatusCode为200.我遇到的问题是,出现的IIS7启动页面返回状态代码200,我没有看到任何其他内容响应对象,允许我验证我们期望实际显示的页面。 I would like to avoid getting the response back and using a StreamReader just to look for a div on the page to verify it's valid (if possible) as they do (similarly) in this link. 我想避免得到回复并使用StreamReader只是在页面上查找div以验证它是否有效(如果可能),因为它们(类似地)在链接中。

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlToCheck);
        request.AllowAutoRedirect = true;

        HttpWebResponse response;
        try
        {
            response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return true;
            }
            return false;
        }
        catch (Exception)
        {
            return false;
        }

Any help is greatly appreciated. 任何帮助是极大的赞赏。

Just read the Response it's already there and waiting! 只需阅读它已存在的Response并等待!

Stream s = response.GetResponseStream();
StreamReader r = new StreamReader(s);
string html = r.ReadToEnd();

// IIS7
if(html.Contains(@"<div id=""container"">
<a href=""http://go.microsoft.com/fwlink/?linkid=66138&amp;clcid=0x409""><img src=""welcome.png"" alt=""IIS7"" width=""571"" height=""411""></a>
</div>") {


}

Investigate the headers that are returned by the other application. 调查其他应用程序返回的标头。 Most probably it will have some additional headers present compared to the IIS splash screen. 与IIS启动画面相比,它最有可能会有一些额外的标题。 For example, it might specify Cache-Control . 例如,它可能指定Cache-Control If your response does not have that header, you can expect it to be the splash screen. 如果您的回复没有该标题,则可以认为它是启动画面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM