Publishing Umbraco site, bundles doesn't work - styles

I have a website made in Umbraco connected to Visual Studio 2012. When I start the project (F5) it looks like it should with CSS and jQuery. In this project we use bundles.
When I publish my website, the bundles can't be found.
"Failed to load resource: the server responded with a status of 404 (Not Found) http://mywebsite.local/bundles/styles" When I look in the console (on my browser) I can find the folder bundles, and the file style. But it is empty.
But on the local site, there is CSS in the style file.
What am I doing wrong? I mean, it's the same code? It's like somewhere on the way half of my code just disappears. I'm also using Optimus as a package to Umbraco, but it doesn't seem to make any difference.
Here's my BundleConfig:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/bundles/custom/css").Include(
"~/css/MasterStyle.css",
"~/css/TopMenu.css",
"~/css/SmallImages.css",
"~/css/SideMenu.css",
"~/css/Footer.css",
"~/css/Support.css",
"~/css/Highlight.css"));
bundles.Add(new ScriptBundle("~/bundles/js/jquery").Include(
"~/scripts/jquery-{version}.js",
"~/scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap/js").Include(
"~/scripts/bootstrap.js"
));
bundles.Add(new ScriptBundle("~/bundles/js").Include(
"~/scripts/TopMenu.js",
"~/scripts/Master.js"));
LogHelper.Info<string>("Bundles Loaded");
//Comment this out to control this setting via web.config compilation debug attribute
BundleTable.EnableOptimizations = true;
}
My Global.Asax (I have not written this, and definitely not sure if this is correct)
<script runat="server">
void Application_Start()
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
</script>
UPDATE:
Check the correct marked answer, I solved it by following that tutorial and used the code that was posted in the answer. I also noticed a minor error in my bundle.config (that I had checked before so that wasn't the main problem).
In my "bundles.Add(new StyleBundle("~/bundles/custom/css")" I have wrong path, for me it should be "~/bundles/styles" instead. And the combination of all this, made it work!

Assuming you're using Umbraco 6 or 7, you could follow the gist here: How to use ASP.NET Bundling and Minifications in Umbraco
However, you should use an ApplicationEventHandler derived class so that you can register them on startup instead of trying to create your own Global.asax.cs class (this is now the recommended way of doing this sort of thing with Umbraco):
public class ArticleEventHandler : Umbraco.Core.ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
An alternative to Bundling is to use the ClientDependency package that comes bundled with Umbraco. I can elaborate on that if you need me to, however there are plenty of examples and documentation on that out there.

Related

Blazor Component (in library) and JSInterop

I've created a Blazor Component within a full Blazor project and all works well.
However, when I move this component to it's own Razor Class Library project, I am now getting an error that I cannot use JSInterop until a connection with the server is made. I am running my code in the OnAfterRenderAsync() method.
I had to alter the code a little when I made the change.
In a full Blazor project, JSInterop is provided for you with DI in the Startup class. But this is not the case with a calss library.
So instead of "#inject JSInterop js" in the page, I had to set it up like this -
private IJSRuntime js { get; set; }
protected override void OnInitialized()
{
js = ScopedServices.GetRequiredService<IJSRuntime>();
}
From the sketchy details available on the web, I'm assuming this gets the service from the Parent project.
Using debugging, I can see that js is NOT null. It does seem to have been set to a valid object.
Can anyone point me in the right direction?
The server pre-renders, so your code will run before there is a client connection to the server. When rendering in OnAfterRenderAsync you should only use IJSRuntime when the firstRender parameter is true, or any point after that, but never before.
Found the solution to my problem and it has rendered my initial question irrelevant.
When I copied my component to it's own class library project, it would not compile. It gave me an error on the line #inject JSInterop js.
This led me to believe that it didn't know how to inject this as it is not set during the Startup of the project, as it is in a Blazor app.
So I cobbled together the code to get a reference via ScopedServices.GetRequiredService().
This did create an object but did not have _clientProxy set which contains the connection to the server.
So digging round I managed to find a complete component library example project at BlazorHelp Website
This did have the JSInterop injected in the Blazor file. So I reverted my code back to the original code that worked in the full project and tried to compile. It gave me the same error. So I deleted the #inject JSInterop js line and typed it in again.
IT RECOGNIZED IT!!!
It still failed to compile, not recognizing a custom type (Pivot) and asking whether I had included a reference to it.
[CascadingParameter] public Pivot OwnerPivot { get; set; }
I deleted the word Pivot and retyped it and, voila, it compiled.
So it looks like there some sort of error in VS2019 or the razor compiler, where deleting code in the source file and re-entering caused it to recognize and compile.

asp.net mvc area not working on iis

I crated area/modular MVC5 application according to this tutorial:
This
it worked perfectly on local. but i got 404 error, when i deployed project on iis and clicked on specified area link.
and i didn't find any solution for that.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Sale
and this is my action links which are perfectly working on local run:
#Html.ActionLink("Sale","Index","Sale",new { Area="Sale"},null)
edited:
public class SaleAreaRegistration:AreaRegistration
{
public override string AreaName
{
get
{
return "Sale";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Sale_default",
"Sale/{controller}/{action}/{id}",
new { controller = "Sale", action = "Index", id = UrlParameter.Optional },
new string[] { "MVCPluggableDemo.Controllers" }
);
}
}
attention: according to the tutorial which i said in first line. i created my module project in another virtual project in solution(the real path is in area folder of main project like"~/ProjectName/Areas/"). but i think the publisher does't understand it...because i don't see any of my module views in deployed path.
its better to completing my help request by this obvious question:
How to deploy MVC project include areas, and the modules which are in areas folder?
Its simply obvious:
Check your page directory. The server cannot locate your the file,
it maybe in different folder.
Also try to Check this.
the main Reason of my problem was this:
VisualStudio doesn't include my Area folder, in publish path..why? i don't know
Solution: no solution yet!..but i added my module dll inside bin folder manually. and created my areas folder and his modules projects solution(dlls' are not not necessary) in main published solution, manually to ..
finally it worked, but i dont thing is the standard solution

Configuration of options from IConfigurationRoot not working?

The following code is snipped from the examples at docs.asp.net.
public void ConfigureServices(IServiceCollection services)
{
// Setup options with DI
services.AddOptions();
// Configure MyOptions using config
services.Configure<MyOptions>(Configuration);
// Configure MyOptions using code
services.Configure<MyOptions>(myOptions =>
{
myOptions.Option1 = "value1_from_action";
});
The call to services.Configure<MyOptions>(Configuration);
causes a compilation error:
cannot convert from 'Microsoft.Extensions.Configuration.IConfigurationRoot' to 'System.Action'
Manually setting up the options works fine. Am I missing something really obvious here?
I had the same problem and I found out you need to add this extension to your project :
Microsoft.Extensions.Options.ConfigurationExtensions
You need to add the following nuget package to your ASP Core Project if you want to configure the strongly typed config in that way.
Microsoft.Extensions.Options.ConfigurationExtensions
The extension methods contained in the package will allow you to configure the strongly typed configuration the way you want to and the way most tutorials show.
services.Configure<MyOptions>(Configuration);
Alternatively, you could add another binder package:
Microsoft.Extensions.Configuration.Binder
Configuration would then look something like this:
services.AddOptions();
services.Configure<MyOptions>(x => Configuration.Bind(x));
This is the downside of having so many modular packaged up extensions. It gets easy to lose track of where functionality exists.

Add WebRole.cs - and have it called - in an existing ASP.NET MVC site converted to web role

I have an ASP.NET MVC 4 site running perfectly well in an Azure WebRole. The ASP.NET MVC project was started on its own, after which I added an Azure Cloud Service project to the solution and added the ASP.NET project/site as one of the 'roles' of the service (so it shows up in the 'Roles' folder).
My problem is that I would like to have working a WebRole.cs file within the ASP.NET MVC project, but no matter what I've tried to do, it appears that when deployed, it just never gets called. OnStart and the override of Run (which I know, must never leave the loop) -- these just apparently never get called.
But if you startup a new CloudService project and add, at that time from the start, an ASP.NET MVC project, it automatically has a WebRole.cs file in it, so my guess is that I need to configure something somewhere for the WebRole.cs (actually speaking, the WebRole class, which inherits RoleEntryPoint) to get called. What might that be?
using System;
using System.Web;
//using Microsoft.WindowsAzure.StorageClient;
using System.Diagnostics;
using System.Threading;
namespace Us.WebUI
{
public class WebRole : Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint
{
public override bool OnStart()
{
return true; //return base.OnStart(); // CALL THIS???
}
public override void Run()
{
while (true) {
Thread.Sleep(TimeSpan.FromSeconds(30));
try {
EmailFuncs.SendEmailToUs("An email from our WebRole?????", "Email me this, email me that.");
}
catch { }
}
}
}
}
UPDATE: Thanks, the question has been answered. But I will add: On doing this, while it clearly was working (fully deployed and in emulator), that suddenly I was having problems doing a full publish of the site. After a azure publish took 3 hours:
Verifying storage account 'xyz'... > Uploading Package... > - Updating... [stayed here for 3 hours], it failed with this error: The server encountered an internal error. Please retry the request. So one thing I was wondering is, did I need to override OnStop in WebRole.cs?
UPDATE 2: Those previous problems were fixed, and had nothing to do with this issue. Actually, I've learned this: If you ever have any warnings generated in your build, Azure often will not work with them even when they don't cause problems locally or in other hosts. Since then, I've been much more studious to tackling build warnings (but critical to this is turning off with warning codes the many warning types you want to ignore!).
Adding a class to your Web Project which inherits from RoleEntryPoint is sufficient, it should just work. Did you try setting a breakpoint in the emulator?
What you might be experiencing is that EmailFuncs.SendEmailToUs requires info from the app/web.config and that this info is not available. You need to know that your WebRole class runs in a different process (not your web application), meaning it's not using your web.config. If you want the WebRole.cs to read info from the configuration file, you'll need to add these settings in WaIISHost.exe.config

Bundling not happening when deployed to production server

I have created a bundle. However its not working when deployed to production server. I am running MVC4 RC
My bundle looks like
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/core").Include("~/Scripts/min/jquery-1.*",
"~/Scripts/min/core.js",
"~/Scripts/min/business-signup.js",
"~/Scripts/min/slider.js",
"~/Scripts/min/label-text.js",
"~/Scripts/min/consumer-account.js",
"~/Scripts/min/modernizr-2*"));
bundles.Add(new StyleBundle("~/Content/min/css").Include(
"~/Content/min/core.css",
"~/Content/min/layout.css",
"~/Content/min/reset.css",
"~/Content/min/sprite.css",
"~/Content/min/pricing.css",
"~/Content/min/homepage-slider.css",
"~/Content/min/transactions.css"));
}
From my layout I call the bundles like
#Styles.Render("~/Content/min/css","~/Content/min/css")
#Scripts.Render("~/bundles/core")
However there is no minifaction or bundling happening. Instead a single request is made for each of the items within the the bundles.
I know the server is working correctly as I have another site running on the same server and the bundling is working ok.
Can anyone see something obvious to what I am doing wrong?
Make sure you are running in Release mode (debug="false" in your web.config). Also notice that there is a bug in the RC that prevents of properly caching the resources server side and thus increasing the CPU usage of your site everytime a request is made to the url that is supposed to serve the bundled and minified version of your resources.

Resources