Last post May 21, 2011 09:26 AM by WombatEd
May 17, 2011 02:55 PM|Isentaur|LINK
right now I have this:
<%@ Page Language="vb" %>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strPage As String = ""
Dim semiPos As Integer
strPage = Request.Url.AbsoluteUri
semiPos = InStr(strPage, ";")
strPage = strPage.Substring(semiPos, strPage.Length - semiPos).Replace("http://", "")
strPage = strPage.Substring(InStr(strPage, "/"), strPage.Length - InStr(strPage, "/"))
If strPage.Contains("/") = False Then
Dim pagepath As String = String.Empty
pagepath = MapPath("/redirect/" & strPage & ".html")
Catch ex As Exception
pagepath = String.Empty
If pagepath <> String.Empty AndAlso IO.File.Exists(pagepath) Then
Response.Redirect("/redirect/" & strPage & ".html")
Response.Redirect("http://ic.longo.com/esuite/home/" & strPage)
Response.Redirect("http://ic.longo.com/" & strPage)
now I want to add a new try statement that will check a different folder and if its there, then redirects them... how do I insert an extra if statement without screwing the whole script up?
thank you in advance, im a super noob
May 17, 2011 03:52 PM|DarthSwian|LINK
You're not really handling the exception now, you're just using try catch as an IF statement. Try catch should be around the execution of something. You're checking if a path is legit, that could be handled another way.
May 21, 2011 09:26 AM|WombatEd|LINK
I use the FileSystem.FileExists method to determine whether a given file exists.
In using try/catch the way you are, you are assuming that the only thing that could cause an exception would be if the file doesn't exist. Murphy's law says "you know what happens when you assume ...?" The .FileExists method actually asks the question
you want answered.