【发布时间】:2021-11-21 18:33:10
【问题描述】:
我想在 asp.net core 中处理 Error StatusCode。
我是在 Startup>Configure 中写的
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404)
{
var page = HttpFailedTemplates.NotFoundPage(context.Request.Path,
context.TraceIdentifier,
DateTime.Now.ToString(),
"نیل سافت",
"https://localhost:44313/");
// in page I have -> <script src='https://localhost:44347/js/libraries/jquery.min.js'></script> in <body> tag
context.Response.ContentType = "text/html";
var buffer = Encoding.UTF8.GetBytes(page);
using (var stream = context.Response.Body)
{
await stream.WriteAsync(buffer, 0, buffer.Length);
await stream.FlushAsync();
}
await next();
}
});
但返回响应后我没有脚本标签
【问题讨论】:
-
您能分享一下您实现功能所遵循的教程吗?
-
我没有任何教程。起初我只是想要一个简单的 html 字符串来响应,它起作用了。但是当我将脚本标签放入字符串中时,它并没有响应。我想在响应正文中写脚本标签
-
HttpFailedTemplates.NotFoundPage 只是我的 html 字符串生成器
标签: javascript c# html asp.net-core .net-5