47 lines
1.1 KiB
C#

#if !NET8
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
#endif
#if NET8
using Microsoft.AspNetCore.Mvc;
#endif
#if !NET8
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
using System.IO;
#endif
namespace Fab2ApprovalSystem.PdfGenerator;
public class BinaryContentResult : ActionResult {
private readonly string contentType;
private readonly byte[] contentBytes;
public BinaryContentResult(byte[] contentBytes, string contentType) {
this.contentBytes = contentBytes;
this.contentType = contentType;
}
#if !NET8
public override void ExecuteResult(ControllerContext context) {
var response = context.HttpContext.Response;
response.Clear();
response.Cache.SetCacheability(HttpCacheability.Public);
response.ContentType = contentType;
using (var stream = new MemoryStream(contentBytes)) {
stream.WriteTo(response.OutputStream);
stream.Flush();
}
}
#endif
}