Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get host name in startup.cs in .net core

I want to get host name/address in .net core application to create connection string dynamically in the ConfigureServices. I have tried so many ways. How can i get the Request detail in startup.cs files

like image 899
Chamara Nillushan Avatar asked Nov 07 '22 18:11

Chamara Nillushan


1 Answers

try this:

    public static string GetAddressIP()
    {
        return Dns.GetHostAddresses(Dns.GetHostName())
            .FirstOrDefault(ha => ha.AddressFamily == AddressFamily.InterNetwork)
            .ToString();
    }
like image 68
Fernando Schneider Leandro Avatar answered Nov 15 '22 09:11

Fernando Schneider Leandro