Get Site Hostname/Name from the startup.cs


How can we get the site name from the manage website (admin tab) by using the startup.cs file 

Edited, Sep 07, 2022 9:42

            var name = app.ApplicationServices.GetService<ISiteDefinitionRepository>().List().First().Name;

this probably works - untested by me 

Sep 07, 2022 10:34
Kumar - Sep 07, 2022 11:59
Thanks for the response, "ApplicationServices" giving an error

public void Configuration(IAppBuilder app)
var name=app.ApplicationServices.GetService
Quan Mai - Sep 07, 2022 12:12
which is the error?
Kumar - Sep 07, 2022 12:20
'IAppBuilder' does not contain a definition for 'ApplicationServices' and no accessible extension method 'ApplicationServices' accepting a first argument of type 'IAppBuilder' could be found (are you missing a using directive or an assembly reference?)

It should be IApplicationBuilder

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

            //other code 

            var name = app.ApplicationServices.GetService<ISiteDefinitionRepository>().List().First().Name;

Sep 07, 2022 12:46
Kumar - Sep 08, 2022 8:47
This one also gives errors.
Error: The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.