“.net 6 Dapatkan nilai appsettings” Kode Jawaban

.net menggunakan variabel appsettings

var connectionString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
connectionString.Expand() // returns "server=db01.mycompany.com;uid=uid;pwd=pwd;Initial Catalog=master;"
Good Goose

.net 6 Dapatkan nilai appsettings

1
2
3
4
5
6
7
8
9
10
11
12
// AppSettingsController.cs
[Route("appsettings")]
public class AppSettingsController : Controller
{
    ...
 
    [Route("first-way")]
    public IActionResult FirstWay()
    {
        return Content(_configuration.GetValue<string>("RoundTheCodeSync:Title"), "text/plain");
    }
}
Doubtful Dugong

.net menggunakan variabel appsettings

<configuration>
    <appSettings>
        <add key="Domain" value="mycompany.com"/>
        <add key="ServerName" value="db01.{Domain}"/>
    </appSettings>
    <connectionStrings>
        <add name="Default" connectionString="server={ServerName};uid=uid;pwd=pwd;Initial Catalog=master;" provider="System.Data.SqlClient" />
    </connectionStrings>
</configuration>
Good Goose

Jawaban yang mirip dengan “.net 6 Dapatkan nilai appsettings”

Pertanyaan yang mirip dengan “.net 6 Dapatkan nilai appsettings”

Lebih banyak jawaban terkait untuk “.net 6 Dapatkan nilai appsettings” di C#

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya