我正在研究以CSV格式导出数据的机制.我JSON使用jQuery以格式发送数据:
var data = JSON.stringify(dataToSend);
$.post('DumpToCSV', { 'data': data });
Run Code Online (Sandbox Code Playgroud)
然后在控制器中我生成一个CSV文件:
public ActionResult DumpToCSV(string data)
{
Response.Clear();
XmlNode xml = JsonConvert.DeserializeXmlNode("{records:{record:" + data + "}}");
XmlDocument xmldoc = new XmlDocument();
//Create XmlDoc Object
xmldoc.LoadXml(xml.InnerXml);
//Create XML Steam
var xmlReader = new XmlNodeReader(xmldoc);
DataSet dataSet = new DataSet();
//Load Dataset with Xml
dataSet.ReadXml(xmlReader);
//return single table inside of dataset
var csv = CustomReportBusinessModel.ToCSV(dataSet.Tables[0], ",");
HttpContext context = System.Web.HttpContext.Current;
context.Response.Write(csv);
context.Response.ContentType = "text/csv";
context.Response.AddHeader("Content-Disposition", …Run Code Online (Sandbox Code Playgroud) 我正在研究ASP .NET MVC 5 Web应用程序.我在用
[Authorize(Roles="administrator")]
public class MyController:Controller{}
有没有办法为控制器动态添加新的授权角色?例如,从数据库或类似的东西中检索此信息,如下所示
[Authorize(Roles=db.MyControllerRoles)]
public class MyController:Controller{}