Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if users visiting the site are on root page or any other page?

Basically I want a certain layout to be used when someone is visiting the root page:

www.foo.com

And another layout when visiting anywhere else:

www.foo.com/asdf

I could use different _Layout files, but since the only change is here, I find that counterproductive.

Here's what I have tried, hopefully it illustrates what I'm trying to accomplish:

@if (HttpContext.Current.Request.Url.ToString() == "some way to check root?")
{
    @RenderBody()
}   
else
{
    <div id="big-kahuna"> <!-- Literally the only change. -->
        @RenderBody()    
    </div>
} 
like image 914
Only Bolivian Here Avatar asked Apr 30 '12 19:04

Only Bolivian Here


2 Answers

if(Request.Url.PathAndQuery == "/") // root;
like image 197
Alex Avatar answered Oct 23 '22 00:10

Alex


if (Request.AppRelativeCurrentExecutionFilePath == "~/")
like image 23
Yaman Avatar answered Oct 22 '22 23:10

Yaman