コード例 #1
0
        public ActionResult StaticFile(string path, ResponseOptions responseOptions)
        {
            responseOptions ??= Options.DefaultStaticFileResponseOptions;
            HttpContextAccessor.HttpContext.Response.Headers.Add("Cache-Control", responseOptions.CacheHeader.ToString());


            if (File.Exists(path))
            {
                var file        = new FileInfo(path);
                var extension   = file.Extension;
                var contentType = MimeTypeMap.GetMimeType(extension);
                return(new FileStreamResult(File.OpenRead(path), contentType));
            }
            return(new NotFoundResult());
        }
コード例 #2
0
 public ActionResult Script(string path, ResponseOptions responseOptions = null)
 {
     path = Path.Combine(ScriptRoot, path);
     return(StaticFile(path, responseOptions));
 }
コード例 #3
0
        public async Task <ContentResult> ViewAsync <T>(string viewName, T model = null, ExpandoObject viewBag = null, ResponseOptions responseOptions = null)
            where T : class
        {
            responseOptions ??= Options.DefaultPageResponseOptions;
            HttpContextAccessor.HttpContext.Response.Headers.Add("Cache-Control", responseOptions.CacheHeader.ToString());

            var html = await RenderAsync(viewName, model, viewBag).ConfigureAwait(false);

            return(new ContentResult
            {
                ContentType = "text/html",
                Content = html,
                StatusCode = StatusCodes.Status200OK
            });
        }