I have declared the QA server path statically in the constant.cs entity framework core, but I need to add dynamically so based environment it should work
example : In mail template
I have one button in that it is linked to QA server appliaction but it should change dynamically ,what configuration I need to do

Vishal JoshiRank #377 · 6.7K reputationPosted Mar 22, 2023, 8:29 AM EDT
Hello
You can use HttpContext class to get the server path and it will automatically work based on the server.
Thanks
Rijwan AnsariRank #82 · 24.2K reputationPosted Mar 22, 2023, 10:26 AM EDT
Hi,
You can use below code.
Directory.GetCurrentDirectory() // root directory //or HttpContext.Request.Host.Value // domainTuhin PaulRank #7 · 71.9K reputationPosted Mar 21, 2023, 9:25 PM EDT
To make the server path configurable based on the environment, you can use the built-in configuration system in .NET Core.
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 21, 2023, 9:27 PM EDT
You can define the configuration settings in the appsettings.json file, like this:
{ "AppSettings": { "ServerPath": "https://qa-server.com" } }and in your Startup.cs file, add the following code to read the configuration settings:
public IConfiguration Configuration { get; } public Startup(IConfiguration configuration) { Configuration = configuration; } public void ConfigureServices(IServiceCollection services) { services.Configure(Configuration.GetSection("AppSettings")); // other service configurations }Here, AppSettings is a class that defines the configuration settings,
public class AppSettings { public string ServerPath { get; set; } }Tuhin PaulRank #7 · 71.9K reputationPosted Mar 21, 2023, 9:28 PM EDT
you can also inject IOptions wherever you need to access the configuration settings
public class MailService { private readonly AppSettings _appSettings; public MailService(IOptions appSettings) { _appSettings = appSettings.Value; } public void SendMail() { string serverPath = _appSettings.ServerPath; // use serverPath to construct the button URL } }