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

Basically, I want a specific layout to be used when someone visits 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 this counterproductive.

Here is what I tried, hopefully this 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> } 
+6
source share
2 answers
 if(Request.Url.PathAndQuery == "/") // root; 
+23
source
 if (Request.AppRelativeCurrentExecutionFilePath == "~/") 
+3
source

Source: https://habr.com/ru/post/914570/


All Articles