net core restapi

最近写了一个工作流引擎,前端是vue,中间是netcore,后端是camunda工作流引擎。
先说说中间层
在vs2019创建asp.net core web应用程序
在实例里面返回的是actionresult<string>上面有一个注解[httpget("id")]这是api的路径
启动之后就可以显示文字,在lanchsettings.json里面更改端口,远程就可以访问了.
点击发布选择文件系统就可以发布到iis上面.大多都是dll文件.
文件服务返回的是fileresult
[HttpGet("{bpmn}")]
public FileResult Getbpmn()
{
string xml = "";
string path = Path.Combine(Directory.GetCurrentDirectory(), "bpmn");
string filepath = Path.Combine(path, "lixiang.bpmn");
if (System.IO.File.Exists(filepath))
{
using(StreamReader sr=new StreamReader(filepath))
{
xml = sr.ReadToEnd();
}
}
byte[] content = System.Text.Encoding.UTF8.GetBytes(xml);
return File(content, "text/xml");
}
然后也可以设置跨域,在startup.cs里面

原文地址:https://www.cnblogs.com/frog2008/p/12119623.html