【发布时间】:2018-02-06 15:01:12
【问题描述】:
我有一个 .NET Core 1.1 应用程序,它在 HomeController 中的操作上设置了自定义属性。鉴于我需要属性逻辑内的配置文件 (appsettings.json) 中的值,是否可以在属性级别访问配置?
appsettings.json
{
"Api": {
"Url": "http://localhost/api"
}
}
HandleSomethingAttribute.cs
public class HandleSomethingAttribute : Attribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
// read the api url somehow from appsettings.json
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
}
HomeController.cs
public class HomeController: Controller
{
[HandleSomething]
public IActionResult Index()
{
return View();
}
}
【问题讨论】:
-
你能分享一些你所拥有的和你想要完成的代码吗?
-
@Shoe 查看更新的问题
-
同样的问题...你能解决它吗?
-
@Dzhambazov 还没有...
标签: asp.net-core-mvc custom-attributes appsettings asp.net-core-1.1