473,770 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

More Questions on Relative URLs and Response.Redire ct

Okay, I asked a question a week or so ago asking for an explanation on
relative URL's and the "~" symbol, and several people explained that
the "~" is only usable when the URL is going to be parsed by ASP.NET.

I have a TreeView control with a hierarchical Category listing of
products. Here is the code in selected node changed event:

protected void CategoryTreeVie w_SelectedNodeC hanged(object sender,
EventArgs e)
{
string newSearchCatego ry =
Server.HtmlEnco de(CategoryTree View.SelectedNo de.ValuePath);
LogEvents.LogIn fo("Category Redirect Location: \"~/
DisplayCategory .aspx?category= " + newSearchCatego ry + "\"");
Response.Redire ct("~/DisplayCategory .aspx?category= " +
newSearchCatego ry);
}

First of all, from the docs I got the impression that the HtmlEncode
call would convert all the spaces and special characters into hex so
they wouldn't interfere with the redirection, but the Log file shows
that they aren't being converted:

7/30/2008 4:27:38 PM INFO Category Redirect Location: "~/
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious
Stones:Amethyst Jewelry"
7/30/2008 4:27:53 PM INFO Category Redirect Location: "~/
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious Stones"

But my main problem is that, if there is a colon character (which I am
using as a path separator) in the query string, the Response.Redire ct
is not parsing the "~", but passing it through to IIS, and I'm getting
a "Resource Not Found" exception, with "Requested URL:"/OBS/~/
DisplayCategory .aspx" The first example in the log excerpt above,
where "Amethyst Jewelry" is a subcategory of "Jewelry with Other Semi-
Precious Stones" fails. The second one, where there is no subcategory
and no colon, succeeds.

Is that a known behavior? Is there another character that I can use
instead of ":" that will avoid the behavior (I don't want to use '/',
because that can occur within the category name.) Or is there some
other method than HTMLEncode that will properly hide the special
characters?

Thanks for your help.
Jul 30 '08 #1
2 3380
Have you tried the ResolveUrl function?

That way you could do:
Response.Redire ct(ResolveUrl(" ~/DisplayCategory .aspx"));

for querystrings I just do:
Response.Redire ct(ResolveUrl(" ~/DisplayCategory .aspx") +
"?myval=someval ue");

you can pass querystrings to the resolveurl method but I like to play it
safe.

Now, something else. Do you realize your query strings are illegal?
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious Stones
This is not a valid querystring. Spaces are an illegal character. Some
browsers may let you get away with it because they'll automatically replace
the spaces with %20, the url code for spaces. Instead, use the Server.
UrlEncode method to make the querystring valid.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

"daveh551" <ge****@gmail.c omwrote in message
news:dd******** *************** ***********@y21 g2000hsf.google groups.com...
Okay, I asked a question a week or so ago asking for an explanation on
relative URL's and the "~" symbol, and several people explained that
the "~" is only usable when the URL is going to be parsed by ASP.NET.

I have a TreeView control with a hierarchical Category listing of
products. Here is the code in selected node changed event:

protected void CategoryTreeVie w_SelectedNodeC hanged(object sender,
EventArgs e)
{
string newSearchCatego ry =
Server.HtmlEnco de(CategoryTree View.SelectedNo de.ValuePath);
LogEvents.LogIn fo("Category Redirect Location: \"~/
DisplayCategory .aspx?category= " + newSearchCatego ry + "\"");
Response.Redire ct("~/DisplayCategory .aspx?category= " +
newSearchCatego ry);
}

First of all, from the docs I got the impression that the HtmlEncode
call would convert all the spaces and special characters into hex so
they wouldn't interfere with the redirection, but the Log file shows
that they aren't being converted:

7/30/2008 4:27:38 PM INFO Category Redirect Location: "~/
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious
Stones:Amethyst Jewelry"
7/30/2008 4:27:53 PM INFO Category Redirect Location: "~/
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious Stones"

But my main problem is that, if there is a colon character (which I am
using as a path separator) in the query string, the Response.Redire ct
is not parsing the "~", but passing it through to IIS, and I'm getting
a "Resource Not Found" exception, with "Requested URL:"/OBS/~/
DisplayCategory .aspx" The first example in the log excerpt above,
where "Amethyst Jewelry" is a subcategory of "Jewelry with Other Semi-
Precious Stones" fails. The second one, where there is no subcategory
and no colon, succeeds.

Is that a known behavior? Is there another character that I can use
instead of ":" that will avoid the behavior (I don't want to use '/',
because that can occur within the category name.) Or is there some
other method than HTMLEncode that will properly hide the special
characters?

Thanks for your help.
Jul 30 '08 #2
On Jul 30, 5:56 pm, "Mark Fitzpatrick" <markf...@fitzm e.comwrote:
Have you tried the ResolveUrl function?

That way you could do:
Response.Redire ct(ResolveUrl(" ~/DisplayCategory .aspx"));

for querystrings I just do:
Response.Redire ct(ResolveUrl(" ~/DisplayCategory .aspx") +
"?myval=someval ue");

you can pass querystrings to the resolveurl method but I like to play it
safe.

Now, something else. Do you realize your query strings are illegal?
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious Stones
This is not a valid querystring. Spaces are an illegal character. Some
browsers may let you get away with it because they'll automatically replace
the spaces with %20, the url code for spaces. Instead, use the Server.
UrlEncode method to make the querystring valid.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

"daveh551" <gee...@gmail.c omwrote in message

news:dd******** *************** ***********@y21 g2000hsf.google groups.com...
Okay, I asked a question a week or so ago asking for an explanation on
relative URL's and the "~" symbol, and several people explained that
the "~" is only usable when the URL is going to be parsed by ASP.NET.
I have a TreeView control with a hierarchical Category listing of
products. Here is the code in selected node changed event:
protected void CategoryTreeVie w_SelectedNodeC hanged(object sender,
EventArgs e)
{
string newSearchCatego ry =
Server.HtmlEnco de(CategoryTree View.SelectedNo de.ValuePath);
LogEvents.LogIn fo("Category Redirect Location: \"~/
DisplayCategory .aspx?category= " + newSearchCatego ry + "\"");
Response.Redire ct("~/DisplayCategory .aspx?category= " +
newSearchCatego ry);
}
First of all, from the docs I got the impression that the HtmlEncode
call would convert all the spaces and special characters into hex so
they wouldn't interfere with the redirection, but the Log file shows
that they aren't being converted:
7/30/2008 4:27:38 PM INFO Category Redirect Location: "~/
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious
Stones:Amethyst Jewelry"
7/30/2008 4:27:53 PM INFO Category Redirect Location: "~/
DisplayCategory .aspx?category= Jewelry with Other Semi-Precious Stones"
But my main problem is that, if there is a colon character (which I am
using as a path separator) in the query string, the Response.Redire ct
is not parsing the "~", but passing it through to IIS, and I'm getting
a "Resource Not Found" exception, with "Requested URL:"/OBS/~/
DisplayCategory .aspx" The first example in the log excerpt above,
where "Amethyst Jewelry" is a subcategory of "Jewelry with Other Semi-
Precious Stones" fails. The second one, where there is no subcategory
and no colon, succeeds.
Is that a known behavior? Is there another character that I can use
instead of ":" that will avoid the behavior (I don't want to use '/',
because that can occur within the category name.) Or is there some
other method than HTMLEncode that will properly hide the special
characters?
Thanks for your help.
Mark,

THANK YOU so much. It's the UrlEncode function that I wanted. I was
using the HtmlEncode by mistake. When I replace HtmlEncode with
UrlEncode (and the corresponding decode function), the problem goes
away.

I'll check out ResolveUrl for future use. I'm learning something with
every mistake (but it sure is a long process!)

Jul 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2053
by: Chris Guimbellot | last post by:
Hello, I am trying to create vanity URLs (I think that's what they are called) that link directly to an item's listing page on my site. Currently, the urls are set up something like the following: http://www.mydomain.com/productinfo.asp?prodID=00000 I am trying to configure them to be something like this:
15
2907
by: Nick K. | last post by:
I recently began maintenance work on a production web server that is located in the root directory of a web server. I moved this into a sub web on my local web server in order to do work on it. I found that there is an include file that references images: <img src = "/images/Header.gif" What worked correctly on the production server breaks on mine because of the absolute address "/images". I removed the absolute address and changed...
2
3171
by: Mark Dengler | last post by:
Is it possible to do a Response.Redirect to multiple URLs? I have tried the following and it simply ignores the first redirect: Response.Redirect("test.aspx", false); Response.Redirect(p.UrlSend, true); I have designed the test.aspx page to simple write a cookie, just to see if it is working and it is not. I have also used to VS.Net
2
4896
by: Paul Bonfanti | last post by:
A customer of ours using .NET 2.0 on Win2003 is seeing relative URLs passed to Response.Redirect() being converted to absolute URLs in the Location header. For example '/test.aspx' becomes 'http://www.myserver.com/test.aspx'. We're not able to reproduce this on our machines. Does anyone know of a setting or configuration that would cause this behavior in Response.Redirect()? Thanks, Paul
3
1522
by: Polaris431 | last post by:
In code, you can type the following: this.Response.Redirect("~/index.aspx"); Is there anything in ASP.NET that you can use in place of strings when referring to URLs? It would be nice to refer to URLs in a strongly typed fashion. Something like: this.Response.Redirect(URLs.Index_ASPX);
2
1501
by: ITistic | last post by:
I am about to start on a migration from a static HTML site to an ASP.NET solution. I've done a ton of these in the past as my primary job duty is developing ASP.NET sites. This is the first project I've come across for a site that has quite a few .HTM pages with good search engine ranking. I want to make sure I do everything I can to retain those rankings at least as far as the URLs are concerned. What I want to do is make sure that when...
11
1788
by: ymic8 | last post by:
Hi everyone, this is my first thread coz I just joined. Does anyone know how to crawl a particular URL using Python? I tried to build a breadth-first sort of crawler but have little success. With wget, if you are more familiar with it than me, how can get it to output the crawled links (links not the actual HTML content) to a file? currently i have something like: wget -q -E -O outfile --proxy-user=username -E...
1
4140
by: Rhiannone | last post by:
Can you use relative addressing when using response.redirect; i.e something that would look like this <% if session("superuser") <> true then response.redirect "../../../edit/logout.asp" %> or does it have to be absolute addressing. For the life of me I can’t find this explicitly written anywhere and I have been using file and virtual to include other pages so I’m curious to know how redirect works. I apologise if this question is silly for...
6
1611
by: daveh551 | last post by:
I need some help (and my apologies if this is not the right group) understanding how to properly form Relative URL's. I'm developing a site (Web Site, not a Web Application if that makes a difference) in VS 2005. The application is called OBS, and it's located C:\Inetpub\wwwroot\OBS. In IIS, it shows a Virtual Directory at that location, running an application "OBS", and with a Starting point "<Default Web Site>\OBS". When I specify...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.