Only Bolivian Here
Only Bolivian Here

Reputation: 36753

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>
} 

Upvotes: 11

Views: 6546

Answers (2)

Yaman
Yaman

Reputation: 1061

if (Request.AppRelativeCurrentExecutionFilePath == "~/")

Upvotes: 4

Alex
Alex

Reputation: 35407

if(Request.Url.PathAndQuery == "/") // root;

Upvotes: 28

Related Questions