我有一个Web API项目,我有一个自定义JSON配置文件,我想在不使用Microsoft.Extensions.Configuration的情况下将其合并到我的项目中。我对此很陌生,但我想避免使用任何.Net Core方法或路由。
以下是涉及的文件摘要:
Web.Config
<appSettings configSource="Config\base\appsettings.json"></appSettings>
appsettings.json
{
"siteURL": "https://helloworld.com",
"TokenSecretKey": "justanothersecret",
"URI.Key": "anotherkey",
"ClientTokenSharedSecret": "somevalue",
"TwoFactorSessionExpirationInMinutes": "43200",
"Email.From": "noreply@thatonesite.com",
"Email.Server": "192.168.1.1",
"Email.Server.User": "user",
"Email.Server.Password": "pword",
}
WebApiConfig.cs
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// Web API routes
config.MapHttpAttributeRoutes();
GlobalConfiguration.Configuration.Formatters.Add(new FormMultipartEncodedMediaTypeFormatter());
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Global.asax.cs
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
我的目标是将这些设置合并到项目中,并能够在项目中的任何地方使用。