What I've been asked to do is make a 'dashboard' app that checks the status
of various servers. If they are down, show an error.
I found/modified this snippet:
---
Try
Dim req As Net.HttpWebRequest = Net.WebRequest.Create("your url")
Dim res As Net.HttpWebResponse = req.GetResponse()
Dim str As IO.Stream = res.GetResponseStream()
Return New IO.StreamReader(str).ReadToEnd()
Catch ex As Exception
Return ex.Message
End Try
End Function
---
2 issues:
1) When I try to call the function ala:
<%=checkURL("http://google.com")%>
I get this error: "Invalid URI: The format of the URI could not be
determined."
Unfortunately, that appears to be a common SharePoint error, so Google
results are a bit cluttered.
2) Even if this does work, will it return anything if the server times out
(the main thing we're looking to check for?
-Darrel
George.
"darrel" <not...@nowhere.com> wrote in message
news:eL3w2Pjq...@TK2MSFTNGP03.phx.gbl...
I think you're basically looking for this :
http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx
This solution doesn't use WebParts, but might give you a few ideas.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"darrel" <not...@nowhere.com> wrote in message news:eL3w2Pjq...@TK2MSFTNGP03.phx.gbl...
You have my permission to walk over here and smack me upside the head for
such a stupid mistake! ;o)
I am completely embarrassed by that one. ;o)
OK, so, that works! Now, to followup...
That returns the actual page. What I need to do is check for specific
errors. For instance, if it can't access the page at all, I get a "Unable to
connect to the remote server".
Is there a master list of these types of errors out there to reference
against?
Or, in general, is this even a good way to go about testing for the status
of a server?
-Darrel
Then your code simply displays it.
So you have for example
<%=checkURL("http://google.com/test.aspx")%>
And your checkURL will do folowing (pseducode, do not know VB well)
Function CheckUrl(sUrl) as String
Dim req As Net.HttpWebRequest
Dim res As Net.HttpWebResponse
Dim str As IO.Stream
Try
req = Net.WebRequest.Create("sUrl")
res = req.GetResponse()
str = res.GetResponseStream()
Return New IO.StreamReader(str).ReadToEnd()
Catch ex As WebException
ex.Response.Dispose()
Return "Connected to server but got an error: " & ex.Message
Catch e As Exception
Return "Could not connect to server: " & e.Message
Finally
if( str Not Is Nothing) Then str.Dispose()
if( res Not Is Nothing) Then res.Dispose()
End Try
End Function
PS: Do not forget to properly close Dispose objectes. You will run out of
resources soon otherwise.
But it only works if you can create your custom test.aspx page on the
server.
If not, you are limmited to was able to connect to server/was not able
to.....
George.
"darrel" <not...@nowhere.com> wrote in message
news:ue$MhtjqI...@TK2MSFTNGP04.phx.gbl...
Also, to run this kind of request in your sharepoint server, whther in a
webpart or not is almost certainly going to need a full trust level setting
in web.config.
Why don't you start by getting the code to work from a simple asp.net page,
and then migrate it into either a sharepoint page or a webpart if you can
get it to work.
Regards
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"darrel" <not...@nowhere.com> wrote in message
news:eL3w2Pjq...@TK2MSFTNGP03.phx.gbl...
I'm avoiding putting anything in SharePoint these days. ;0)
-Darrel
Good idea, though we really don't need anything that robust.
I found some suggestions one being to load the page, regex out the TITLE
tag, and compare it to what you think it should be. If it's different, then
either an error page loaded, or an error was returned.
The one unknown is what if the server just doesn't respond? I assume you'd
get some sort of time-out error. I'm just not quite sure how to test that
particular aspect yet. I'll have to wait for one of our servers to go down
;)
-Darrel