Programmatically check the IIS7 splash screen

I have an ASP.Net 3.5 web application (C #) where I need to programmatically check if another of our sites is working (not ASP.Net). I currently have a method with the following code that checks the StatusCode 200. The problem I am facing is that the IIS7 popup page that appears returns a status code of 200 and I don’t see anything else in the response object. which will allow me to check the page that we expect is actually displayed. I would like to avoid getting a response and using StreamReader only to find the div on the page to check its validity (if possible), as they do (similarly) in this .

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.

+4
source share
2 answers

Just read Response , he's already there and waiting!

 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>") { } 
+5
source

Examine the headers returned by another application. Most likely, it will have some additional headers compared to the IIS splash screen. For example, it can specify Cache-Control . If your answer does not have this heading, you can expect it to be a splash screen.

0
source

Source: https://habr.com/ru/post/1484844/


All Articles