473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Understanding != when rewriting URLs

Hi guys

I have a web app I'm developing in C#. I have a UrlRewrite HTTP Handler,
which seems to work, apart from when I ask it to do something if NOT.

Here's the directory structure...

/default.aspx
/gallery/default.aspx
/gallery/viewartist.aspx

On the main page, I have a link to the gallery section which links to
"/gallery/". From there, I have a number of fake links to artists, e.g.
"/gallery/artist1/", "/gallery/artist2/", etc

The idea is to use URL rewriting to forward those fake links to
"viewartist?artist_id=artist1"

But I still want links to "/gallery/" to work.

Here's the code...

if (url.Contains("/gallery/"))
{
if (url.EndsWith("/gallery/") != true)

waveApp.Context.RewritePath(ConfigurationManager.A ppSettings["BaseUrl"] +
"gallery/viewartist.aspx");
}

I don't handle the /gallery/ option, because it has a default.aspx, so
that's sorted.

The problem is, as I've got the code now, it ALWAYS goes to viewartist.aspx.
You can never get to /gallery/default.aspx.

Can someone explain why if (url.EndsWith("/gallery/") != true) seems to get
ignored, and the waveApp.Context.Rewrite... always gets fired?!

Thanks, Dan.
Jan 5 '08 #1
3 1238
musosdev <mu*******@community.nospamwrote:

<snip>
Can someone explain why if (url.EndsWith("/gallery/") != true) seems to get
ignored, and the waveApp.Context.Rewrite... always gets fired?!
Is that definitely, definitely your code, exactly as it is? I only ask
because you haven't got braces around the inside statement, which is
okay - unless you've got a rogue semicolon in your actual code.

Personally I'd write it as a single "if" expression:

if (url.Contains("/gallery/") && !url.EndsWith("/gallery/"))
{
waveApp.Context.RewritePath
(ConfigurationManager.AppSettings["BaseUrl"] +
"gallery/viewartist.aspx");
}

Have you stepped in with the debugger to see what's going on?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 5 '08 #2
Why not trace the url variable and see what the value is?

When you go to "/gallery/", it ends up going to the default URL which in
this case is "default.aspx". As a result, I bet you are getting
"/gallery/default.aspx" and then processing that, thinking you are getting
"/gallery/".

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"musosdev" <mu*******@community.nospamwrote in message
news:7F**********************************@microsof t.com...
Hi guys

I have a web app I'm developing in C#. I have a UrlRewrite HTTP Handler,
which seems to work, apart from when I ask it to do something if NOT.

Here's the directory structure...

/default.aspx
/gallery/default.aspx
/gallery/viewartist.aspx

On the main page, I have a link to the gallery section which links to
"/gallery/". From there, I have a number of fake links to artists, e.g.
"/gallery/artist1/", "/gallery/artist2/", etc

The idea is to use URL rewriting to forward those fake links to
"viewartist?artist_id=artist1"

But I still want links to "/gallery/" to work.

Here's the code...

if (url.Contains("/gallery/"))
{
if (url.EndsWith("/gallery/") != true)

waveApp.Context.RewritePath(ConfigurationManager.A ppSettings["BaseUrl"] +
"gallery/viewartist.aspx");
}

I don't handle the /gallery/ option, because it has a default.aspx, so
that's sorted.

The problem is, as I've got the code now, it ALWAYS goes to
viewartist.aspx.
You can never get to /gallery/default.aspx.

Can someone explain why if (url.EndsWith("/gallery/") != true) seems to
get
ignored, and the waveApp.Context.Rewrite... always gets fired?!

Thanks, Dan.
Jan 5 '08 #3
Hi Nicholas/Jon,

John - I originally had the statement as a single IF but it wouldn't work so
I tried it as 2 instead.

In fact, Nicholas' suggestion has solved the problem. I've changed the
second expression to !url.EndsWith("/gallery/default.aspx") and it works fine.

I guess I always thought the URL was the requested URL, and default.aspx
wouldn't have been added yet. Oh well, I've learnt something :)

Thank you both!
"Jon Skeet [C# MVP]" wrote:
musosdev <mu*******@community.nospamwrote:

<snip>
Can someone explain why if (url.EndsWith("/gallery/") != true) seems to get
ignored, and the waveApp.Context.Rewrite... always gets fired?!

Is that definitely, definitely your code, exactly as it is? I only ask
because you haven't got braces around the inside statement, which is
okay - unless you've got a rogue semicolon in your actual code.

Personally I'd write it as a single "if" expression:

if (url.Contains("/gallery/") && !url.EndsWith("/gallery/"))
{
waveApp.Context.RewritePath
(ConfigurationManager.AppSettings["BaseUrl"] +
"gallery/viewartist.aspx");
}

Have you stepped in with the debugger to see what's going on?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 5 '08 #4

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

Similar topics

6
by: Gordan | last post by:
Hi, here's my problem. On my pages I have URL souch as these "page.php?id=2&subpage=3&param=65". For security reasons I would like to add another parameter. It would be created like this...
0
by: Jim Jaworski | last post by:
I have a page of archived newspaper articles. This week I did the "good thing" and placed them in a <div id="content"> wrapper. Now when I select an item the page blinks in Mozilla. Though in...
0
by: Dan | last post by:
I have a huge site written in asp and i have now written a isapi filter of sorts in asp.net to rewrite my dynamic urls to search engine friendly urls and translate them on iis to the true address....
6
by: Smokey Grindle | last post by:
I use to know how to do this in .net 1.1, but not sure in 2.0 (cant even remember 1.1 its been 2yrs since I did ASP.net last) but say I have this site that is dynamic ...
4
by: Mark Olbert | last post by:
I've written a composite custom control which I would like to have update its design-time display when one of several properties changes at design time. These custom properties are not simply the...
1
by: wizardsm25 | last post by:
Hi I have a basic grasp of java and now I am trying to get to know php as I would like a particular thing to happen onload and I dont think it is able to be done through java I beleive it has to be...
2
by: striawe | last post by:
Is there any way to rewrite urls in php without using xampp server? I rewrite when working on xampp, but I am trying to do this in another way without using htaccess file. For example through...
3
by: IanW | last post by:
Hi, I'd just like some advice on the best way to throw a 404 when rewriting urls. The scenario is as follows: My url is /products/redwidgets This redirects fine to...
3
by: Toni | last post by:
Does anyone have a recommended method of rewriting URLs with classic ASP? For example, if the browser shows the Friendly URL www.mydomain.com/blue_widget my app will show the following Content...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.