#If DEBUG and Response.Redirect

D

Dot net work

I have noticed that this:

Response.Redirect("/MyLocalDirectory/MyPage.aspx")

seems to be a lot quicker than this:

Response.Redirect(sDirectoryString & "MyPage.aspx")


In local development mode, I need to have sDirectoryString equal to my
local folder structure, but when I upload the project to a webserver,
the sDirectoryString needs to contain a value equal to the webserver
folder structure.

Rather than have the sDirectoryString variable scenario above which
seems to really slow the Redirect operation down, would this be a much
better approach:

#If DEBUG Then
Response.Redirect("/MyLocalDirectory/MyPage.aspx")
#Else
Response.Redirect("/MyServerDirectory/MyPage.aspx")
#End If

Thanks a lot, from dnw.
 
K

Karl Seguin

Don't like.

(a) the first shouldn't be "a lot" quicker than the second...it shouldn't be
noticable by any means
(b) You shoulnd't hard code paths into the application...what if you have a
3rd server, like a testing one, you'll add another compilation constant and
#else if that?

My suggestion is to stick with the 2nd one and figure out why it's so much
slower. Also, sDirectoryString should be fed from a config file (web.config
is fine) so that it can easily be changed.

Karl
 
H

Hans Kesting

Dot said:
I have noticed that this:

Response.Redirect("/MyLocalDirectory/MyPage.aspx")

seems to be a lot quicker than this:

Response.Redirect(sDirectoryString & "MyPage.aspx")


In local development mode, I need to have sDirectoryString equal to my
local folder structure, but when I upload the project to a webserver,
the sDirectoryString needs to contain a value equal to the webserver
folder structure.

Rather than have the sDirectoryString variable scenario above which
seems to really slow the Redirect operation down, would this be a much
better approach:

#If DEBUG Then
Response.Redirect("/MyLocalDirectory/MyPage.aspx")
#Else
Response.Redirect("/MyServerDirectory/MyPage.aspx")
#End If

Thanks a lot, from dnw.

If a path is processed by asp.net (as with Response.Redirect) you can use a
"hidden" feature: When you start the path with a ~, then that will be replaced
by the application path. So you can just say:

Response.Redirect("~/MyPage.aspx")

and it works both on your dev-machine and your live server.

Hans Kesting
 
D

Dot net work

Thanks for your suggestion.

Karl Seguin said:
Don't like.

(a) the first shouldn't be "a lot" quicker than the second...it shouldn't be
noticable by any means
(b) You shoulnd't hard code paths into the application...what if you have a
3rd server, like a testing one, you'll add another compilation constant and
#else if that?

My suggestion is to stick with the 2nd one and figure out why it's so much
slower. Also, sDirectoryString should be fed from a config file (web.config
is fine) so that it can easily be changed.

Karl
 
D

Dot net work

That's cool, thanks.

I have found a nice overall solution for my dilemna.

I now have the following folder structure inside my project:

ASPXs/Home 'Home page just goes in here for neatness.
ASPXs/Authentication
ASPXs/NonAuthentication

When I need to move about, all I need to do is:

Response.Redirect("../<one of the three folders
above>/MyChosenPage.aspx

This will work on any machine with the easy-to-create folder structure
above.

(Previously, I had the Default.aspx sitting in a different sub folder
level in my project, and it was causing all sorts of "path access type
problems".)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top