We're hosting SSIS reports on our servers and we are storing their paths in a sql server table. From .Net, I want to be able to make sure the path entered is correct.
This should return "true" because there's a report there, for example:
http://server/Reports/Pages/Viewer.aspx?%2fShopFloor%2fProduction+by+Turn&rs:Command=Render
This should return false.
ht开发者_开发知识库tp://I am an invalid location/I am laughing at you/now I'm UEEing
I was looking at WebRequests, but I don't know if that's the route I should be taking.
Any help would be appreciated. Thanks!
You can try making a HEAD request to validate that the resource exists. With a HEAD request, you would only need the HTTP Code (200 = Success, 404 = Not Found) without consuming resources or excess memory to download the entire resource. Take a look at HttpWebRequest class for performing the actual request.
Do a http HEAD
request to the URL, which should just fetch headers. This way you dont need to download the entire page if it exists. from the returned headers(if there are any) you should be able to determine if its a correct URL or not.
I'm unsure of the exact layout of your network, but if the .net application has visibility to the location the reports are stored, you could use File.Exists()
. Otherwise, mellamokb and red-X have the right idea.
精彩评论