외부 라이브러리 내부에있는 정적 파일을 제공하려고했습니다.외부 라이브러리의 정적 파일 제공
저는 이미 컨트롤러와 뷰를 사용하고 있지만 해당 라이브러리에서 리소스 (자바 스크립트, 이미지 등)를로드 할 수 없습니다.
이"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"embed": [
"Views/**/*.cshtml",
"wwwroot/**"
]
},
사람이 뭐가 잘못 됐는지 말해 줄 수 : 여기
는 외부 라이브러리의 project.json 내 Startup.cs
여기public void ConfigureServices(IServiceCollection services)
{
//...
var personAssembly = typeof(PersonComponent.Program).GetTypeInfo().Assembly;
var personEmbeddedFileProvider = new EmbeddedFileProvider(
personAssembly,
"PersonComponent"
);
services
.AddMvc()
.AddApplicationPart(personAssembly)
.AddControllersAsServices();
services.Configure<RazorViewEngineOptions>(options =>
{
options.FileProviders.Add(personEmbeddedFileProvider);
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...
var personAssembly = typeof(PersonComponent.Program).GetTypeInfo().Assembly;
var personEmbeddedFileProvider = new EmbeddedFileProvider(
personAssembly,
"PersonComponent"
);
app.UseStaticFiles();
//This not work
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new CompositeFileProvider(
personEmbeddedFileProvider
)
});
}
그리고 내 buildOptions 설정을 무엇입니까?
이 여러분 모두 감사합니다 (미안 내 영어 나쁜)
를 만들 때 이 단지
RequestPath
변수를 작성하여 수행합니다. 내용을 외부 라이브러리의 루트로 옮겨보십시오. – Tseng저에게 도움이 되었어요! 감사! 그러나 외부 플러그인에 Bower를 사용하고 싶기 때문에 여전히 루트로 컨텐츠를 이동하지 않고 대안을 찾고 있습니다. 다시 게시 할 내용 –
나는 자신의 제공 업체를 작성하지 않고 가능하다고 생각하지 않습니다. 'EmbeddedFileProvider'는 https://github.com/aspnet/FileSystem/blob/rel/1.1.0/src/Microsoft.Extensions.FileProviders.Physical/PhysicalFileProvider.cs#와 같은 루트 경로를 지원하지 않습니다. L39이 루트 경로는 요청 미들웨어가 파일의 위치를 알지 못하기 때문에'PhysicalFileProvider'를'wwwroot'로 설정합니다. 미들웨어를 사용하면 'wwwroot'가없는 경로 만 미들웨어에 전달됩니다. – Tseng