您的位置:首页 > 文旅 > 旅游 > 变色龙app制作教程_网页制作工具中flash可以让网页动起来_有什么推广软件_360搜索引擎网址

变色龙app制作教程_网页制作工具中flash可以让网页动起来_有什么推广软件_360搜索引擎网址

2025/3/31 18:39:33 来源:https://blog.csdn.net/qq_36437991/article/details/146376024  浏览:    关键词:变色龙app制作教程_网页制作工具中flash可以让网页动起来_有什么推广软件_360搜索引擎网址
变色龙app制作教程_网页制作工具中flash可以让网页动起来_有什么推广软件_360搜索引擎网址

razor类库

在这里插入图片描述
在这里插入图片描述
新建PluginController

using Microsoft.AspNetCore.Mvc;namespace RazorClassLibrary1.Controllers
{public class PluginController : Controller{public IActionResult Index(){return View();}}
}

Views下Plugin下新建Index.cshtml

@{ViewBag.Title = "插件页面";
}
<h1>我是插件页面</h1>

新建mvc
在这里插入图片描述
在这里插入图片描述
修改program.cs

using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
using Microsoft.Extensions.FileProviders;
using RazorClassLibrary1.Controllers;namespace WebApplication1
{public class Program{public static void Main(string[] args){var builder = WebApplication.CreateBuilder(args);var assembly = typeof(PluginController).Assembly;// Add services to the container.builder.Services.AddControllersWithViews().AddApplicationPart(assembly).AddRazorRuntimeCompilation();builder.Services.Configure<MvcRazorRuntimeCompilationOptions>(options =>{options.FileProviders.Add(new EmbeddedFileProvider(assembly));});var app = builder.Build();// Configure the HTTP request pipeline.if (!app.Environment.IsDevelopment()){app.UseExceptionHandler("/Home/Error");}app.UseStaticFiles();app.UseRouting();app.UseAuthorization();app.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");app.Run();}}
}

运行项目
在这里插入图片描述
访问Plugin
在这里插入图片描述

普通类库

新建类库项目
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
修改csproj

<ItemGroup><FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

Plugin2Controller.cs

using Microsoft.AspNetCore.Mvc;namespace ClassLibrary1.Controllers
{public class Plugin2Controller : Controller{public IActionResult Index(){return View();}}
}

VIews\Plugin2\Index.cshtml

@{ViewBag.Title = "插件2页面";
}
<h1>我是插件2页面</h1>

Index.cshtml设置为嵌入资源
在这里插入图片描述
修改Program.cs

using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
using Microsoft.Extensions.FileProviders;
using RazorClassLibrary1.Controllers;
using ClassLibrary1.Controllers;
using Microsoft.AspNetCore.Mvc.ApplicationParts;namespace WebApplication1
{public class Program{public static void Main(string[] args){var builder = WebApplication.CreateBuilder(args);var assembly = typeof(PluginController).Assembly;var assembly2 = typeof(Plugin2Controller).Assembly;var part1 = new AssemblyPart(assembly);var part2 = new AssemblyPart(assembly2);builder.Services.AddControllersWithViews().ConfigureApplicationPartManager(apm =>{apm.ApplicationParts.Add(part1);apm.ApplicationParts.Add(part2);})//需要安装Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.AddRazorRuntimeCompilation();builder.Services.Configure<MvcRazorRuntimeCompilationOptions>(options =>{options.FileProviders.Add(new EmbeddedFileProvider(assembly));options.FileProviders.Add(new EmbeddedFileProvider(assembly2));});var app = builder.Build();// Configure the HTTP request pipeline.if (!app.Environment.IsDevelopment()){app.UseExceptionHandler("/Home/Error");}app.UseStaticFiles();app.UseRouting();app.UseAuthorization();app.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");app.Run();}}
}

访问Plugin2
在这里插入图片描述

如果遇到Cannot find compilation library location for package ‘System.Security.Cryptography.Pkcs‘错误需要升级System.Security.Cryptography.Pkcs

参考

https://www.cnblogs.com/readafterme/p/18470211
https://learn.microsoft.com/zh-cn/aspnet/core/mvc/advanced/app-parts?view=aspnetcore-8.0
https://gitee.com/urselect/urshop
https://blog.csdn.net/u011511086/article/details/144530878

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com