如何从Razor页面(Blazor WebAssembly)中的launchSettings.json文件访问属性?
我在launchSettings.json文件中创建了这些属性。现在我需要访问Student.razor页面中的API-1和API-2值。 我试着这样使用它如何从Razor页面(Blazor WebAssembly)中的launchSettings.json文件访问属性?,blazor,blazor-client-side,asp.net-blazor,blazor-webassembly,Blazor,Blazor Client Side,Asp.net Blazor,Blazor Webassembly,我在launchSettings.json文件中创建了这些属性。现在我需要访问Student.razor页面中的API-1和API-2值。 我试着这样使用它 "APIs": { "API-1": "http://localhost:5000/student", "API-2": "http://localhost:5001/teacher"} 您
"APIs": {
"API-1": "http://localhost:5000/student",
"API-2": "http://localhost:5001/teacher"}
您不需要为此使用launchsettings,应该使用appsettings.json 在wwwroot中创建一个appsettings.json,并将api配置放在其中
List<Student> students = await http.GetFromJsonAsync<List<Student>>("API-1");
然后在需要的任何位置注入IConfiguration。
e、 g
及
您不需要为此使用launchsettings,应该使用appsettings.json 在wwwroot中创建一个appsettings.json,并将api配置放在其中
List<Student> students = await http.GetFromJsonAsync<List<Student>>("API-1");
然后在需要的任何位置注入IConfiguration。
e、 g
及
launchSettings.json仅用于开发。prodlaunchSettings中没有launchSettings。json仅用于开发。中没有启动设置prod@Shruti,这是正确的答案…你为什么不接受它@Shurti,这是正确的答案…你为什么不接受它!?
@inject Microsoft.Extensions.Configuration.IConfiguration config
List<Student> students = await http.GetFromJsonAsync<List<Student>>(config["APIs:API-1"]);