public class PermissionCheckApplicationModelConvention : IApplicationModelConvention
{
public void Apply(ApplicationModel application)
{
foreach (var controllerModel in application.Controllers)
{
var controllerType = controllerModel.ControllerType;
var controllerName = controllerModel.ControllerName;
controllerModel.Actions.ToList().ForEach(actionModel =>
{
var actionName = actionModel.ActionName;
var parameters = actionModel.Parameters;
// 根据判断条件,操作修改actionModel
});
// 根据判断条件,操作修改ControllerModel
}
}
}
services.AddMvc().Configure<MvcOptions>(options =>
{
options.ViewEngines.Clear();
options.ViewEngines.Add(typeof(ThemeViewEngine));
});
JsonInputFormatter XmlDataContractSerializerInputFormatter
HttpNoContentOutputFormatter StringOutputFormatter JsonOutputFormatter XmlDataContractSerializerOutputFormatter
public Task DoSomethingAsync()
{
// 返回Task
}
public void DoSomething()
{
// Void方法
}
public string GetString()
{
return null; // 返回null
}
public List<Data> GetData()
{
return null; // 返回null
}
public object GetData()
{
return"The Data"; // 返回JSON
}
public string GetString()
{
return"The Data"; // 返回字符串
}
services.Configure<MvcOptions>(options => options.OutputFormatters.RemoveAll(formatter => formatter.Instance is JsonOutputFormatter) );
public class Product2Controller : Controller
{
[Produces("application/json")]
//[Produces("application/xml")]
public Product Detail(int id)
{
return new Product() { ProductId = id, ProductName = "商品名称" };
}
}
[Produces("application/json")]
public class JsonController : Controller { }
public class HomeController : JsonController
{
public List<Data> GetMeData()
{
return GetDataFromSource();
}
}
services.Configure<MvcOptions>(options =>
options.Filters.Add(newProducesAttribute("application/json"))
);
[ResponseCache(Duration = 100)]
public IActionResult Index()
{
return Content(DateTime.Now.ToString());
}
| 属性名称 | 描述 |
|---|---|
| Duration | 缓存时间,单位:秒,示例:[code]Cache-Control:max-age=100[/code] |
| NoStore | true则设置[code]Cache-Control:no-store[/code] |
| VaryByHeader | 设置Vary header头 |
| Location | 缓存位置,如将Cache-Control设置为public, private或no-cache。 |
[ResponseCache(CacheProfileName = "MyProfile")]
public IActionResult Index()
{
return Content(DateTime.Now.ToString());
}
public void ConfigureServices(IServiceCollection services)
{
services.Configure<MvcOptions>(options =>
{
options.CacheProfiles.Add("MyProfile",
new CacheProfile
{
Duration = 100
});
});
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有