473,785 Members | 2,167 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 3381
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
2910
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
4897
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
1789
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
9489
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
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
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
10100
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
8988
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...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.