admin管理员组文章数量:1429064
I am creating an ASP.NET Core application that will contain several areas. Where would I add JavaScript files that are specific to a certain area (usually I put them into the wwwroot\js Folder. Is there something like this for an area?)?
I am creating an ASP.NET Core application that will contain several areas. Where would I add JavaScript files that are specific to a certain area (usually I put them into the wwwroot\js Folder. Is there something like this for an area?)?
Share Improve this question asked Apr 6, 2017 at 13:37 AlexanderAlexander 1,0616 gold badges21 silver badges38 bronze badges 1- 1 I found plete response in this post: [ASP.Net MVC Core: Javascript files in Areas along with Views (.cschtml) ](taimooradilbadshah.blogspot./2017/05/…) – Sayed Abolfazl Fatemi Commented Jun 29, 2019 at 13:01
2 Answers
Reset to default 4"Where would I add JavaScript files"? Answer is you can choose your location based on your requirements and convenience. Default location is content root i.e. wwwroot folder and its subfolders however ASP.Net Core doesn't stop you from placing those static files outside "wwwroot" folder. However if you want to place it outside default content folder i.e. wwwroot you need to tell asp core where your content files are located. Way to tell asp core is configure StaticFiles middleware as follows:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
RequestPath = new PathString("/StaticFiles")
});
Here MyStaticFiles folder is outside wwwroot and located just inside your project directory.
Now if you want to access any file inside MyStaticFiles folder then it will be using following path.
http://<myapp>/StaticFiles/myscript.js
Note "StaticFiles" in above path and in middleware configuration.
The use of server-based solutions will not work in a stand-alone JavaScript file. I use the following:
function getBaseURL() {
var re = new RegExp(/^.*\//);
return re.exec(window.location.href);
}
This seems to work both locally and when deployed.
本文标签: Location of JavaScript files in ASPNET Core AreasStack Overflow
版权声明:本文标题:Location of JavaScript files in ASP.NET Core Areas - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745422562a2657966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论