Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with response.redirect

Status
Not open for further replies.

nivini

Programmer
Mar 24, 2004
64
In my code i have :
<%response.redirect server.MapPath("/folder1/horse.asp")%>
now this yields "the page cannot be displayed"
when i change it to:
<%response.redirect "it works, and i can see 'horse.asp'.
What is the reason for this error?
many thanks
nivini
 
I think you are right DotNetGnat.

Anyway it would be easy to test by adding something like this:
Response.Write server.MapPath("/folder1/horse.asp") & "<BR>"
Response.End

If you just slip that in at the top of the page and run it once you'll see the path ... I think it will be just as DNG predicted. Remember to take that test code out afterwards though...
 
The MapPath Method:

Server.MapPath(path)

path -> A relative or virtual path to map to a physical path. If this parameter starts with / or \, it returns a path as if this parameter is a full virtual path. If this parameter doesn't start with / or \, it returns a path relative to the directory of the .asp file being processed

more info at
that should clear your doubt...

-DNG
 
DNG, many many thanks for your replays
the file im redirecting FROM is located in a nearby folder on my machine (c:/inetpub/I will use the full path eventually, but still i want to know why the redirection with the server.mappath doesnot work.??
many thanks IA
nivini
 
The reason is that a redirect is actually a command sent to the browser that instructs the browser to request a different page.

If the browser requests C:\blah\blah it will be looking for the file on its own hard drive...
 
you should pass the virtual path and NOT THE PHYSICAL PATH for server.mappath to work...

-DNG
 
may be i am wrong here...i got confused...Sheco please shed some light and make it clear...

-DNG
 
DNG
Thanks for the explaination
many many thanks
nivini
 
Web applications don't really have state in the same way that normal windows programs do. Sometimes we forget this because sessions allow us to do a decent job of approximating state... but thing of all the problems people have trying to simulate state. For any single page you've jump to go through programmatic hoops to figure out who is this user? Has he logged in? What pages in the application did he already view and all that stuff.

Redirect is another weak link in the chain. It does not MOVE the user to another page, it sends a command to the user ASKING them to request some other page. Usually this happens without a hitch because most people have their browser security settings low enough to automatically follow any redirect, but not everyone...

Because a redirect is simply asking the browser to request another page, the URL that you give them to ask for must be something they can reach... something they can understand... If you give them a local file path then that wont work... actually it MIGHT work if you were sitting there using a browser on the web server itself but otherwise no dice.

Sometimes you realy want to be using Server.Transfer or Server.Execute instead of Response.Redirect... but they have their own issues. You've just got to lay out what you are ultimately trying to accomplish and see which fits best to make the best approximation of application state.
 
thanks for the explanation...so then, i think we can state...

you should pass the virtual path and NOT THE PHYSICAL PATH for server.mappath to work unless you are using browser on the server machine(i mean the web server itself)...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top