This project is read-only.

Am I on the frontpage?

Topics: ASP.NET 2.0, Business Logic Layer, Controls, Themes
Jan 11, 2009 at 11:20 PM

Is there an easy way of knowing if I'm on my (set) frontpage of my BE-website? I'd like to show some controls - which I add programmatically - only in this case.

Thank you
Jan 12, 2009 at 2:56 AM
In this recent discussion, it was brought up to check the Page title to see if you're on the front page (not really a great method).  I just took a look at the BE core code and saw that it determines if you're on the front page by looking at the Url.  This is probably a better approach.  The code is ...

if (path == Utils.RelativeWebRoot.ToUpperInvariant() + "DEFAULT.ASPX" && context.Request.QueryString.Count == 0)

... where "path" is context.Request.Path.ToUpperInvariant().
Jan 14, 2009 at 11:58 AM
Thank you for your answer, but it doesn't work.

Utils.RelativeWebRoot.ToUpperInvariant() returns "/WEBSITE/
and the path-variable with Request.Path.ToUpperInvariant() returns _always_ "/WEBSITE/PAGE.ASPX" even the URL in the address bar doesn't show "page.aspx"...

Is there another solution of getting to know if I'm on the frontpage?

Thank you
Jan 14, 2009 at 5:24 PM
The reason the 'path' variable always returns "/WEBSITE/PAGE.ASPX" is probably because you have a Page marked as 'Is Front Page'.  In this case, the blog's frontpage is going to end in PAGE.ASPX instead of DEFAULT.ASPX.  All you need to do is adjust the IF statement so it checks for either case.

string path = Request.Path.ToUpperInvariant();
string rwr = Utils.RelativeWebRoot.ToUpperInvariant();
if (Request.QueryString.Count == 0 && (path == rwr + "DEFAULT.ASPX" || path == rwr + "PAGE.ASPX"))

Also, just FYI, 'page.aspx' is in the path variable, but isn't in the address bar because BE is rewriting the Url for the server side request.  The rewritten Url isn't exposed to the client.
Jan 14, 2009 at 10:19 PM
Thanks again for your answer, but it still doesn't work.

Request.QueryString.Count == 0 is never true, even the page doesn't show any querystring.
So i decided to delete this additional statement and just to ask if "(path == rwr + "DEFAULT.ASPX" || path == rwr + "PAGE.ASPX"))". This work fine, but also includes normal "pages".

So I still can't know if I'm on my set frontpage.

Thanks for any answers!

Jan 14, 2009 at 10:56 PM
You're right, sorry.  When using a page marked as 'Is Front Page', BE is rewriting the path to include the querystring.

I think I found something that should pretty much always work regardless if you're using a Page marked as 'Is Front Page'.

if (Request.RawUrl.ToUpperInvariant() == Utils.RelativeWebRoot.ToUpperInvariant() + "DEFAULT.ASPX")

Let me know if that works ... it seems reliable after running it thru a few tests.
Jan 19, 2009 at 9:42 PM
Yes, thank you very much. Now it works fine.

In another post I asked why there is no control <blog:LinkList ... />? Do you have a solution for "simulating" this control? All others do exist, except the LinkList-Control.