

But before checking the final output lets put the break point and check whether we are able to access the detail or not.
#Write on pdf app settings code#
Now lets write code to display the accessed configuration setting in controller "Title" ] = "Home Page" we have done run the code and check the output. StringBuilder.Append( "EnableSsl: " + enablessl + "" ) StringBuilder.Append( "Port: " + port + "" ) StringBuilder.Append( "DefaultCredentials: " + defaultcredentials + "" )
#Write on pdf app settings password#
StringBuilder.Append( "Password: " + password + "" ) StringBuilder.Append( "FromEmail: " + fromemailid + "" ) StringBuilder.Append( "UserName: " + username + "" ) StringBuilder.Append( "Host: " + host + "" ) StringBuilder stringBuilder = new StringBuilder() Var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile( "appsettings.json", optional: false ) Now we will add the code to display it on controller view. The name space for ConfigurationBuilder is. In above code i have used ConfigurationBuilder to read the appsettings.json file. String enablessl = config.GetValue( "Smtp:EnableSsl" ) String port = config.GetValue( "Smtp:Port" ) String defaultcredentials = config.GetValue( "Smtp:DefaultCredentials" ) String password = config.GetValue( "Smtp:Password" ) String fromemailid = config.GetValue( "Smtp:FromEmail" ) String username = config.GetValue( "Smtp:UserName" )

String host = config.GetValue( "Smtp:Host" )

Other Articles: Retrieve Connection String From Web.config In ASP.net Using C#.Net (AppSettings,ConnectionStrings), Access Connection String In Asp.Net Core 6 Controller From appsettings.json C# , appsettings.json Connection String Value Access in Asp.net Core Controller, Access Connection String In Asp.Net Core 6 ClassLibrary From appsettings.json C# | appsettings.json Connection String Value Access in Asp.net Core ClassLibrary, Access Connection String In DbContext File From appsettings.json C# In Asp.Net Core 6.Īfter this we will add the below code into the controller to access the email server setting or SMTP server setting from appsetting.json file.ĬonfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile( "appsettings.json", optional: false ) In Appsettings.json file we will first add the email server setting as shown below. So for this first we will create a new asp.net core web application and add open the Appsettings.json file. In this article i will show you how you can access or read the email setting from Appsettings.json file in asp.net core 6 / MVC application using c#.net.
