Page redirect problem

J

june

I am using the following code to re-direct a page.

Dim strfile As String = "http://S4" &
Me.dgResults.DataKeys(e.Item.ItemIndex)
Response.Redirect(Server.UrlPathEncode(strfile))

where Me.dgResults.DataKeys(e.Item.ItemIndex) produces a string such
as:
/olp/audit/current/A010-311005-fhf-01.doc - i.e. to download a Word
document

This code works fine until I reach a document name which has a
"special" character in it such as A010#0704-311005-fhf-01.doc

Does anyone have an idea how I can get around this problem?
 
K

Karsten Samaschke [MVP]

Hi,
This code works fine until I reach a document name which has a
"special" character in it such as A010#0704-311005-fhf-01.doc

Rename ist. If you redirect the browser to such a document, its name
will be interpreted as Document A010, Anchor 0704...01.doc. The browser
won't request the right document.

Another solution (which is more secure, btw): Do redirects to a script
or a handler and pass the wanted document as parameter. Then check the
path in the script and deliver the file using Response.WriteFile().

--
Karsten Samaschke
IT-Consulting, IT-Development, IT-Training
5x MS MVP ASP / ASP.NET, Germany
Homepage: http://www.ksamaschke.de
Weblog: http://www.karsan.de
- - - - - - - - - - - - - - - - - - - - - - - - - -
My Weblog: http://www.karsan.de
My Books: http://books.ksamaschke.de
 

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