我有一种方法在Windows Server 2016上发布后无效。
ASP.NET CORE 2.0 - MVC
发布方式:文件系统。
所以我的名声很低,我无法添加图片......
我有数据库和表:
ETP_Main (ETP_MainId , ..., ... )
ETP_Title (ETP_TitleId, ETP_MainId, ..., ... )
and etc.
构建我的项目:
页:
查看索引(有一些链接)
<a asp-action="ControlPage" asp-route-
id="ETP_MainId"></a>
查看ControlPage
@model GiproApp.Models.Repository.ViewModel
<form asp-action="CreateWordFile" asp-route-id="@Model.Mains.ETP_MainId">
<input type="submit" class="btn btn-info" value="Dowload">
</form>
//***code***
我有一个控制器:
namespace GiproApp.Controllers
{
public class ETPController : Controller
{
private readonly DataBaseContext _context;
}
//***code***
[HttpGet]
public async Task<IActionResult> ControlPage(int id)
{
ETP_Main main = await _context.ETP_Mains.SingleOrDefaultAsync(m => m.ETP_MainId == id);
//***code***
}
不起作用方法CreateWordFile
[HttpPost]
public async Task<IActionResult> CreateWordFile(int id)
{
ETP_Main main = await _context.ETP_Mains.SingleOrDefaultAsync(m => m.ETP_MainId == id);
var webRoot = _env.WebRootPath;
var pathEtp = Path.Combine(webRoot, "files", "Etp.docx");
var pathDoc = Path.Combine(webRoot, "files", "Doc.docx");
using (WordprocessingDocument wEtp = WordprocessingDocument.Open(pathEtp, true))
{
string docText = null;
using (StreamReader sr = new StreamReader(wEtp.MainDocumentPart.GetStream()))
{
docText = sr.ReadToEnd();
sr.Close();
}
if (title.ObjName != null) docText = Regex.Replace(docText, "AKEY0", title.ObjName);
else docText = Regex.Replace(docText, "AKEY0", " ");
//***code***
using (WordprocessingDocument wDoc = WordprocessingDocument.Open(pathDoc, true))
{
using (StreamWriter sw = new StreamWriter(wDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
sw.Write(docText);
sw.Close();
}
}
}
return RedirectToAction(nameof(Dowload));
}
方法下载工作。
[HttpPost]
public IActionResult Dowload()
{
var webRoot = _env.WebRootPath;
var pathDoc = Path.Combine(webRoot, "files", "Doc.docx");
return base.PhysicalFile(pathDoc, "application/msword", "Doc.docx");
}
错误:
http://192.168.0.158/ETP/CreateWordFile/30
HTTP 404 NOT FOUND
它不应该引用:CreateWordFile / 30
应该下载文件。
我的NuGet:
DocumentFormat.OpenXml
jQuery
Microsoft.AspNetCore.All
Microsoft.AspNetCore.Server.IISIntegration
Microsoft.VisualStudio.Web.CodeGeneration.Design
当我在本地计算机上运行程序时,一切正常。 发布后为什么不起作用?