我在Visual Studio 2017中有一个.NET Core解决方案,它是针对.NET 4.7框架构建的.
在主Web应用程序中,有一个依赖项菜单,可将参考分解为逻辑类别(Analyzers,Assemblies,NuGet,Projects).
在帮助项目中,它只有一个参考菜单,里面的所有内容都混杂在一起.有没有办法在这里获得与Web应用程序相同的处理?
我正在尝试从另一个项目加载剃刀视图。我已经经历了几个不同的兔子洞,但到目前为止我还没有找到一种方法来完成这项工作。然而,根据我的研究,似乎有两种主要方法可以实现这一目标。
一种选择是使用嵌入式资源,然后将嵌入式文件提供程序连接到 razor 中。我可能是错的,但我认为这是 .net core 2.1 之前的方法。我的理解是,在 2.1 Razor 视图中,Razor 视图是在构建时编译的。将其设置为嵌入将保存实际文件,这对于旧的运行时编译很有用。
// Add the embedded file provider to be used with razor view templates
var viewAssembly = typeof(CoreStartup).GetTypeInfo().Assembly;
var fileProvider = new EmbeddedFileProvider(viewAssembly);
services.Configure<RazorViewEngineOptions>(o => o.FileProviders.Add(fileProvider));
services.AddTransient<ITemplateService, TemplateService>();
Run Code Online (Sandbox Code Playgroud)
另一种方法是将视图放入区域文件夹中。我什至找到了一个示例项目,它表明您完全可以做到这一点!但是,我一直无法找到获得相同结果的方法。
作为参考,这里是我尝试用来查找和渲染剃刀视图的服务。我需要从中获取 html 输出以帮助创建 html 电子邮件模板。
namespace TestApp.Services
{
using System;
using System.IO;
using System.Threading.Tasks;
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.ViewFeatures;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Options;
using Serilog;
public class TemplateService : …
Run Code Online (Sandbox Code Playgroud) 我有提供全局错误处理的自定义中间件。如果捕获到异常,则应使用参考编号记录详细信息。然后我想将用户重定向到错误页面并只显示参考号。我的研究表明 TempData 应该是理想的,但它似乎只能从控制器上下文中访问。我尝试将参考编号添加到HttpContext.Items["ReferenceNumber"] = Guid.NewGuid();
但此值通过重定向丢失。
中间件如何通过重定向传递信息?我是否只需要将数字放在查询字符串中?
model-view-controller tempdata asp.net-core asp.net-core-middleware
我试图在打字稿中使用枚举,但它们的类型检查似乎不太一致。为什么我可以TestEnum.Foo === 'foo'
在没有警告的情况下进行检查,但尝试传递'foo'
到接受 a 的函数TestEnum
会导致错误。
describe('Test enum functionality', () => {
enum TestEnum {
Foo = 'foo',
Bar = 'bar'
}
// I expected this to work as TestEnum.Foo === 'foo'
test('Can pass string to enum', () => {
const func = (x: TestEnum) => {}
// Error: Argument of type '"foo"' is not assignable to parameter of type 'TestEnum'
func('foo');
});
// Surprised that this worked after I couldn't pass in a string …
Run Code Online (Sandbox Code Playgroud) .net-core ×1
asp.net-core ×1
c# ×1
dependencies ×1
enums ×1
razor ×1
reference ×1
tempdata ×1
typescript ×1