Im trying to Build my own ScriptManagerController
which will load JS files from another project.
These files are saved as resource files.
This is the code i used in Net451
var url= Page.ClientScript.GetWebResourceUrl(this.GetType(), "namespace.CustomComboBox.js") + "?JSReloader=" + DateTime.Now.ToFileTime()
var sc= "<script src="+url+"></script>"
The problem is that NetAppCore 2.0 dose not have ClientScriptManager
or Page
which then i cant use GetWebResourceUrl
I could still load the js file content and then load it throw HtmlString
which in my case is really bad, my js file content is really big so i want to avoid it.
Is there a workaround you could help me with.
Update
Well this is what i did, I created a Controller that return a filestream in the other project and used MapRoute to mapp the namespace of the controller.
If you have any other solution will still give you the points.
app.MapRoute(
name: "xxx",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index" },
namespaces: new string[] { "namespace" }
Follow steps 4, 5, and 6 of this post including-static-resources-in-razor-class-libraries
Create a configuration file.
internal class EditorRCLConfigureOptions : IPostConfigureOptions<StaticFileOptions> { private readonly IHostingEnvironment _environment; public EditorRCLConfigureOptions(IHostingEnvironment environment) { _environment = environment; } public void PostConfigure(string name, StaticFileOptions options) { // Basic initialization in case the options weren't initialized by any other component options.ContentTypeProvider = options.ContentTypeProvider ?? new FileExtensionContentTypeProvider(); if (options.FileProvider == null && _environment.WebRootFileProvider == null) { throw new InvalidOperationException("Missing FileProvider."); } options.FileProvider = options.FileProvider ?? _environment.WebRootFileProvider; // Add our provider var filesProvider = new ManifestEmbeddedFileProvider(GetType().Assembly, "resources"); options.FileProvider = new CompositeFileProvider(options.FileProvider, filesProvider); } }
(Optional) Create an extension class (you could also skip and use the services.ConfigureOptions
line directly in the Startup
class.
public static class EditorRCLServiceCollectionExtensions { public static void AddEditor(this IServiceCollection services) { services.ConfigureOptions(typeof(EditorRCLConfigureOptions)); } }
Add the new service to the startup class's ConfigureServices
method:
services.AddEditor();
Now you can use a file path just like a Content
file, but for Embedded Resources!
<script src='@(pathToEmbeddedResource)' />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.