Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

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.

like image 263
Robert Hill Avatar asked Oct 28 '25 19:10

Robert Hill


1 Answers

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();
    }
like image 69
Truc Avatar answered Oct 30 '25 22:10

Truc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!