Robert Hill
Robert Hill

Reputation: 353

How to get domain name in ASP.NET Core 2.0 Razor Pages

I'm trying to determine the current domain name from within the Startup.Cs module of an ASP.NET Core 2.0 Razor pages application. The website will be bound to several different domains and I want to load the appropriate _layout/theme based on this.

I have been searching, but I can't figure out how to determine which domain was used to reach the site.

Any help would be greatly appreciated.

Thanks.

Upvotes: 4

Views: 6266

Answers (1)

Truc
Truc

Reputation: 462

You have access to the request object if your controller inherits from Controller

public IActionResult About()
    {
        ViewData["Message"] = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";

        return View();
    }

Upvotes: 7

Related Questions