당신은 INopStartup.Configure (IApplicationBuilder 응용 프로그램)의 사용자 지정 구현에서는이
뭔가를 시도 할 수
application.Use(async (context, next) =>
{
using (var customStream = new MemoryStream())
{
// Create a backup of the original response stream
var backup = context.Response.Body;
// Assign readable/writeable stream
context.Response.Body = customStream;
await next();
// Restore the response stream
context.Response.Body = backup;
// Move to start and read response content
customStream.Seek(0, SeekOrigin.Begin);
var content = new StreamReader(customStream).ReadToEnd();
// Write custom content to response
await context.Response.WriteAsync(content);
}
});
그리고 귀하의 맞춤보다 더 ResultFilterAttribute
public class MyAttribute : ResultFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext context)
{
try
{
var bytes = Encoding.UTF8.GetBytes("Foo Bar");
// Seek to end
context.HttpContext.Response.Body.Seek(context.HttpContext.Response.Body.Length, SeekOrigin.Begin);
context.HttpContext.Response.Body.Write(bytes, 0, bytes.Length);
}
catch
{
// ignored
}
base.OnResultExecuted(context);
}
}
그리고 결과
희망이 올바른 방법으로 얻을 수 있습니다.
고마워요. 잘 작동합니다 (Y) –
이 솔루션을 nopCommerce에 사용하면 문제가 발생합니다. _INopStartup.Configure_ 메소드에서 ** next() **를 먼저 호출 한 다음 ** 응답 스트림 **을 복원하면 이미지와 스크립트가 사용자 측에로드되지 않고 ** Response Content-Length 오류가 발생합니다. 불일치 : 너무 많은 바이트가 쓰여짐 ** 먼저 응답 스트림을 복원 한 후 next()를 호출하면 ** filterContext.HttpContext.Response.Body.Seek() 메서드를 찾을 수 없습니다. **에서 오류가 발생합니다. –