D
daveh551
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 CategoryTreeView_SelectedNodeChanged(object sender,
EventArgs e)
{
string newSearchCategory =
Server.HtmlEncode(CategoryTreeView.SelectedNode.ValuePath);
LogEvents.LogInfo("Category Redirect Location: \"~/
DisplayCategory.aspx?category=" + newSearchCategory + "\"");
Response.Redirect("~/DisplayCategory.aspx?category=" +
newSearchCategory);
}
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.Redirect
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.
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 CategoryTreeView_SelectedNodeChanged(object sender,
EventArgs e)
{
string newSearchCategory =
Server.HtmlEncode(CategoryTreeView.SelectedNode.ValuePath);
LogEvents.LogInfo("Category Redirect Location: \"~/
DisplayCategory.aspx?category=" + newSearchCategory + "\"");
Response.Redirect("~/DisplayCategory.aspx?category=" +
newSearchCategory);
}
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.Redirect
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.