src/EasyFrameWork/Mvc/RazorPages/ViewRenderService.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Easy.Mvc.Plugin;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;
using System.Linq;
namespace Easy.Mvc.RazorPages
{
public class ViewRenderService : IViewRenderService
{
private readonly IRazorViewEngine _viewEngine;
private readonly ITempDataProvider _tempDataProvider;
private readonly IWebHostEnvironment _hostingEnvironment;
private readonly IHttpContextAccessor _httpContextAccessor;
public ViewRenderService(IRazorViewEngine viewEngine, ITempDataProvider tempDataProvider, IWebHostEnvironment hostingEnvironment, IHttpContextAccessor httpContextAccessor)
{
_viewEngine = viewEngine;
_tempDataProvider = tempDataProvider;
_hostingEnvironment = hostingEnvironment;
_httpContextAccessor = httpContextAccessor;
}
public string Render(string viewPath)
{
return Render(viewPath, string.Empty);
}
public string Render<TModel>(string viewPath, TModel model)
{
ActionContext actionContext = new ActionContext(_httpContextAccessor.HttpContext, new RouteData(), new ActionDescriptor());
string pluginPath = $"~/wwwroot/{Loader.PluginFolder}/";
string actualViewPath = viewPath;
if (_hostingEnvironment.IsDevelopment() && actualViewPath.StartsWith(pluginPath))
{
actualViewPath = actualViewPath.Replace(pluginPath, DeveloperViewFileProvider.ProjectRootPath);
}
else if (_hostingEnvironment.IsProduction() && actualViewPath.StartsWith(pluginPath))
{
string filePath = actualViewPath.Replace("~/", string.Empty);
var fileInfo = _hostingEnvironment.ContentRootFileProvider.GetFileInfo(filePath);
if (!fileInfo.Exists)
{
actualViewPath = $"~/{string.Join("/", actualViewPath.Split('/').Skip(4))}";
}
}
ViewEngineResult viewResult = _viewEngine.GetView(null, actualViewPath, true);
后面还有 29 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。