I've got a HttpHandler which outputs XML to the client to play video, it outputs the url to the video, video name etc... Validates the request etc.
However sometimes when i upload new video the main URL doesn't pickup the file from the CDN so i have to use a different URL to go directly to one of the main servers.
For example the CDN url is:
http://videos.****.net/
One of the server urls is:
http://videos1.****.com/
What i want to do is check to see if the file can be reached off the .net url before posting it back to the user.
So
if http://videos.****.net/ar/ar_1003_scene_1.ext response then
> post http://videos.****.net/ar/ar_1003_scene_1.ext to client
else
> post http://videos1.****.com/ar/ar_1003_scene_1.ext to client
I hope that makes sense.
I thought of doing a WebRequest/WebResponse but i don't want the file to come back, i just wanna know if its there or not. My site is on a single server while all the video is on a CDN.
Dont forget if the file is within filesystem reach (on the same computer or within network range) then you could use System.IO to check the file exists.
Public Class UrlValidity
Public Shared Function IsValid(ByVal Url As String) As Boolean
Dim sStream As Stream
Dim URLReq As HttpWebRequest
Dim URLRes As HttpWebResponse
Try
URLReq = WebRequest.Create(Url)
URLRes = URLReq.GetResponse()
sStream = URLRes.GetResponseStream()
Dim reader As String = New StreamReader(sStream).ReadToEnd()
Return True
Catch ex As Exception
‘Url not valid
Return False
End Try
End Function
End Class
I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance
Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support
If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
Marked as answer by Rex Lin - MSFT on Jun 19, 2007 02:48 AM
I kinda gave up after a couple of days and ended up forgetting i posted here. I changed it slightly but i get a response fine.
HttpWebRequest URLReq;
HttpWebResponse URLRes;
try
{
URLReq = (HttpWebRequest)WebRequest.Create("*url to movie file*");
URLRes = (HttpWebResponse)URLReq.GetResponse();
if (URLRes.StatusCode == HttpStatusCode.OK)
return true;
}
catch (Exception ex)
{
return false;
}
My question tho is, does it just get a Response is does it actually fetch the file? These files are 50-200mb in size and the last thing i wanna do is check to see if it exists only to have it fetch the file.
I can't use File.Exists() because the files are on another server. Website is on 1 server, video is on a Content Delievery Network.
For me this is invalid URL, so i except this to redirect to 404 page which I have configured in IIS, if the page not found Instead.. this page is loading default.aspx without CSS, Scripts, and UserControls.
Could someone help, how to identify this kind of invalid URL and redirect to 404?
@ dfordurai, You could just use the customErrors node in the <system.web> section of the web.config (This code is usually commented out in a new website in VS2008). This would catch all the 404's
and send them to a page called filenotfound.aspx. See example below.
Natural Caus...
Member
355 Points
123 Posts
Checking if a URL Exists
Jun 14, 2007 09:32 AM|LINK
I've got a HttpHandler which outputs XML to the client to play video, it outputs the url to the video, video name etc... Validates the request etc.
However sometimes when i upload new video the main URL doesn't pickup the file from the CDN so i have to use a different URL to go directly to one of the main servers.
For example the CDN url is:
http://videos.****.net/
One of the server urls is:
http://videos1.****.com/
What i want to do is check to see if the file can be reached off the .net url before posting it back to the user.
So
if http://videos.****.net/ar/ar_1003_scene_1.ext response then
> post http://videos.****.net/ar/ar_1003_scene_1.ext to client
else
> post http://videos1.****.com/ar/ar_1003_scene_1.ext to client
I hope that makes sense.
I thought of doing a WebRequest/WebResponse but i don't want the file to come back, i just wanna know if its there or not. My site is on a single server while all the video is on a CDN.
(i can't post the url because it's NSFW)
Edit: Why do posts not auto format?!?
Rex Lin - MS...
All-Star
17422 Points
2116 Posts
Re: Checking if a URL Exists
Jun 18, 2007 04:03 AM|LINK
HI, Natural:
Dont forget if the file is within filesystem reach (on the same computer or within network range) then you could use System.IO to check the file exists.
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support
If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
Natural Caus...
Member
355 Points
123 Posts
Re: Checking if a URL Exists
Jul 12, 2007 04:51 AM|LINK
Hey, Thanks for the reply.
I kinda gave up after a couple of days and ended up forgetting i posted here. I changed it slightly but i get a response fine.
My question tho is, does it just get a Response is does it actually fetch the file? These files are 50-200mb in size and the last thing i wanna do is check to see if it exists only to have it fetch the file.
I can't use File.Exists() because the files are on another server. Website is on 1 server, video is on a Content Delievery Network.
Cheers.
dfordurai
Member
12 Points
6 Posts
Re: Checking if a URL Exists and redirect to 404
Aug 24, 2010 02:30 AM|LINK
Is that possible to check, if the URL exist in the website?
If the URL is invalid then redirect to 404 .
For Example:
Valid URL is http://localhost/ABC/default.aspx
Output will be the default.aspx webpage, that’s fine.
Note: this default.aspx page includes come Scripts, CSS, and UserControl – all works fine.
Invalid URL is http://localhost/ABC/default.aspx/images/default.aspx
For me this is invalid URL, so i except this to redirect to 404 page which I have configured in IIS, if the page not found Instead.. this page is loading default.aspx without CSS, Scripts, and UserControls.
Could someone help, how to identify this kind of invalid URL and redirect to 404?
FYR – Folder Structure
C:\inetpub\wwwroot\ABC\
\CSS\
\Scripts\
\UserControls\
\Images\
\Default.aspx
\Default.aspx.cs
Thanks in Advance,
csgulden
Member
14 Points
2 Posts
Re: Checking if a URL Exists and redirect to 404
Sep 16, 2010 11:05 PM|LINK
@ dfordurai, You could just use the customErrors node in the <system.web> section of the web.config (This code is usually commented out in a new website in VS2008). This would catch all the 404's and send them to a page called filenotfound.aspx. See example below.
<customErrors mode="On" defaultRedirect="error.aspx">
<error statusCode="404" redirect="filenotfound.aspx" />
</customErrors>
web.config redirect