Render Script bundle from other application - asp.net-mvc

I am authoring an MVC application that is hosted by another MVC hosting solution. The dll from the client app is copied into the bin folder of the hosting app. The Views, Views/Shared, Scripts, Content, ... are all copied to the hosting project as well. In the Hosting solution, I've created an Area that will act as the base for any of the client apps and dynamically create routes to the view via a warmup routine. This part works great.
However, my javascript bundles do not render as I would hope, I believe it is because they files aren't being found. In this client app, I have two JS files...for simplicity's sake, javascript1.js and javascript2.js. The are located in my Scripts folder of my client app: C:\MyClientApp\Scripts\*.js. Upon compilation, a post build event copies the files to the Hosting solution: C:\MyHostingApp\Scripts\MyClientApp\*.js.
In an app startup (also done in the warmup routine), my bundle is built:
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(MyClientApp.AppStart), "Start")]
namespace MyClientApp
{
public static class AppStart
{
public static void Start()
{
ConfigureBundles();
}
private static void ConfigureBundles()
{
var bundle = new ScriptBundle("~/MyClientApp/Js")
.Include("~/Scripts/javascript1.js")
.Include("~/Scripts/javascript2.js");
BundleTable.Bundles.Add(bundle);
}
}
}
In my view, I would like to call #Scripts.Render("~/MyClientApp/Js"). This doesn't work though, nothing is rendered. My assumption is that it is looking for that bundle under the root of the application, not under the MyClientApp. In an attempt to properly locate the bundle, I tried writing an HtmlHelper extension to resolve the bundle...though the best I could get it to do was to resolve the bundle name into my source and ultimately it seemed that there must be a simpler way to accomplish this. Any ideas on how to render these bundles? Is there something I can do with the routing engine, comparable to Views to locate JS (and eventually css) files?
Thanks!

Bundling currently uses a VirtualPathProvider to find the files for the bundles. The built in VirtualPathProvider only knows about files within the application. If you want to be able to reference files outside of the app, you could try implementing your own VPP that can retrieve files outside of the app.

Related

Adding a static web page to a Vapor server

I have a Vapor server API running in Heroku supporting an iOS app. I want to create a simple landing page for my app and I would like to host it in my existing Vapor server. How could I do that?
Vapor actually has a built-in middleware that makes this very easy. First, make sure you have a Public directory at the root of your Vapor project. Then you can put your static HTML page in there, along with any CSS and JS files it might rely on.
Next, you just need to add FileMiddleware to your application's middleware (docs):
let file = FileMiddleware(publicDirectory: app.directory.publicDirectory)
app.middleware.use(file)
Now you can access any of the files in your Public directory using their relative directory path as the path in the URL to your app. For example, if you have a static directory in your Public directory, and put a home.html file in it, you request the page by going to http://localhost:8080/static/home.html in your browser.

What is the equivalent of StyleBundle and ScriptBundle in node.js/expressjs/ejs?

I'm working on a project for my web applications course. One of the requirements for the project is to use the MEAN stack (mongo, express, angular, node). I also use EJS as the view engine.
I'm new to node, mongo and express, but I do have a lot of experience with ASP.NET MVC/WebAPI.
In ASP.NET MVC there's a library called System.Web.Optimization containing StyleBundle and ScriptBundle classes. One can create a bundle and add stylesheets/scripts to it, then link it to the view with Scripts.Render("path/to/bundle") (or Styles.Render(...)), which, depending on the app's configuration, would be replaced with either links to every file in the bundle, or a single link to a server-generated file containing the contents of all files inside that bundle, minified.
Is there an equivalent of this functionality in node/express/EJS? For the project I'm not really interested in the auto-minification functionality (but it could be good to know), but more in the bundling mechanism.

Add new bundle outside Application_Start

I just found bundle of asp.net MVC is amazing. It help me compress all those javascript&css files.
However, I think adding all static files in BundleConfig.cs is hard. (I feel that to register all static files which are in diffrent modules, different pages when appliction start is not a good idea.)
For example, some people of my team want to develop a partial view. In that partial view, there are some static files: stac1.js, stac2.js, style1.css, style2.css.
I prefer a solution: Register those files in an independent file of that module/page.
When some one access that module/page, those static files will be compressed.
Is that solution existed?
I don't understand why you prefer that when some one access that module/page, those static files will be compressed. It's better to compress this files in Application_Start because Application_Start is launch one once for all users application. The compression will be exectued only once, if you execute compression for each access of page/module, the loading time will be longer for final user

Are files in public folder accessible to outside world? - Rails

This is a simple question but I can't seem to find an answer for it anywhere. If you store some files (say some static PDFs) in your public directory, is there a way that someone who isn't authorized to view those files, can view them by typing in a url like example.com/public/static_document.pdf? If so, can you disable this in Rails?
The public is definitely public and open to people guessing the URL.
Check out Ruby On Rails - Securing Downloads Area for someone else asking similar.
I store these generally in Rails.root/secure_files and then use send_file in the Controller to authorize and send these files.
The public folder contains the static files and compiled assets for the client to read. The folder by default is accessible to anyone visiting your site. Test it by typing in a slug of the folder name currently in your public folder.

How do I serve static files from mvc without using content folder?

I want to be able to have a folder which allows regular access like the \content folder except that it holds a ClickOnce application. I can't seem to be able to achieve this using Mvc, but I'd like to have this folder accessible without Mvc seeing it as a controller action.
I tried using routes.Ignore(theUrl), but this seemed to have no effect.
There are two ways you can do this. The first is where you are currently going, which is to satisfy it with routing. You should be able to use the following to ignore the intended route:
routes.IgnoreRoute("...")
However, this might not be the right approach from a security stand point. I would recommend you define an explicit action to download your click-once exe. Have a look at this q/a as an example of using the FileContentResult class.
The reason for this is that you can control security for that file without having to open up access levels to other directories.
Edit: If this is for an entire directory, you can still follow this same approach.
Set up the folder as a virtual folder in the website on IIS. then you can set the url in the code to point to the machine serving the request and to the virtual folder on the web server.

Resources