Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 13th, 2007, 02:08 AM
Authorized User
 
Join Date: Jan 2007
Location: Islamabad, Punjab, Pakistan.
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aliirfan84
Default Repone.Redirect() problem

I want to open file and using Response.Redirect(@"c:\path\filename.pdf",true) in page load event.But it doesn't work and 'Page can'be diplayed' error is shown?

Please tell me how can I do this?

Thanks

__________________
Regards,
Ali Irfan
  #2 (permalink)  
Old June 13th, 2007, 02:12 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You need to pass a virtual URL to the Redirect method, not a physical URL. E.g.:

Response.Redirect(@"/SomePath/filename.pdf",true)

where /SomePath/filename.pdf is a valid location in your web site.

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old June 13th, 2007, 03:28 AM
Registered User
 
Join Date: Feb 2007
Location: Madison, SD, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to condescendent Send a message via Yahoo to condescendent
Default

Why should we add @ before the virual path?

On the textbook, it use this way:

Response.Redirect("page1.aspx").

what's the funciton of @ and "true"?

Thank you.

I am a database programmer and .Net programmer
  #4 (permalink)  
Old June 13th, 2007, 03:36 AM
Authorized User
 
Join Date: Jan 2007
Location: Islamabad, Punjab, Pakistan.
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aliirfan84
Default

Dear if u want to map path or use escape sequence characters like '/' in string object, then u have to use '@' to preserve actual value. Unless otherwise '/' will lost.

Secondly, 'ture' means that current instance/page will end after displaying other page.

  #5 (permalink)  
Old June 13th, 2007, 08:29 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

To clarify a little:

According to MSDN the boolean argument:

"Indicates whether execution of the current page should terminate."

When called with true, "Redirect() calls End() which raises a ThreadAbortException exception upon completion." (from MSDN)

This is an important feature because you might want to redirect the browser without letting any more code execute. For example, if you need to check for the existence of some resource (file, database record, etc.) before continuing and wish to redirect the user away from the page if the resource doesn't exist, you could force the termination of the page execution to avoid running any code that uses that resource. My personal opinion is that one should program around that possibility and finish the page gracefully when possible. However, you can't prevent postback events from firing, so there is a legitimate reason for forcing termination.

The @ notation has nothing to do with the method being used. It's a string formatting notation in C# that forces the program to ignore escaped characters inside the literal string. Thus, these two examples are equivelant:

filePath = "C:\\Temp\\myfile.txt";
filePath = @"C:\Temp\myfile.txt";

The forward slash [/] is not an escaped character. You can do this without problem:

redirectUrl = "folder/somepage.aspx";

-Peter


Similar Threads
Thread Thread Starter Forum Replies Last Post
Response.Redirect Problem msbsam ASP.NET 2.0 Basics 0 February 10th, 2007 03:28 AM
Problem with redirect/replace gorros Javascript 4 March 11th, 2006 07:37 AM
problem with redirect.. joeore PHP Databases 2 February 17th, 2004 02:54 PM
repsponse.redirect problem skipinator ASP.NET 1.0 and 1.1 Basics 3 June 8th, 2003 02:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.