Sitecore 8.2 MVC 无法让 MVC 包工作

Sitecore 8.2 MVC can't get MVC bundles to work

我一直在尝试设置 Sitecore 8.2 MVC 并使用 MVC 包将我的所有脚本和样式拉到主布局上。我一直在 运行 解决问题,因为不再使用全局文件和最佳实践我应该使用管道初始化 buldler。

BundleConfig.cs

using System.Web;
using System.Web.Optimization;
using Sitecore;
using Sitecore.Pipelines;

namespace MySite.Web.Pipelines
{

    public class RegisterPlatformBundles
    {
        [UsedImplicitly]
        public virtual void Process(PipelineArgs args)
        {
            RegisterBundles(BundleTable.Bundles);
        }
        private void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new StyleBundle("~/bundles/styles").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));

        }

    }

我尝试使用以下配置文件将其添加到管道中。

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeGlobalFilters, Sitecore.Mvc']"
           type="MySite.Web.Pipelines.RegisterPlatformBundles, MySite" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>

当我尝试 运行 网站时出现以下错误。任何帮助我设置它的建议,甚至是正确的路径都会很棒。谢谢

Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Exception: Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)).]
Sitecore.Diagnostics.Error.Raise(String error, String method) +137
Sitecore.Configuration.DefaultFactory.CreateType(XmlNode configNode, String[] parameters, Boolean assert) +308
Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert) +71
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +165
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, Boolean assert) +68
Sitecore.Pipelines.CorePipelineFactory.GetObjectFromType(XmlNode processorNode) +91
Sitecore.Pipelines.CorePipelineFactory.GetProcessorObject(XmlNode processorNode) +145
Sitecore.Pipelines.CoreProcessor.GetMethod(Object[] parameters) +144
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +470
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
Sitecore.Nexus.Web.HttpModule.Application_Start() +262
Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app) +704
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +618
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343

[HttpException (0x80004005): Could not resolve type name: MySite.Web.Pipelines.RegisterPlatformBundles, MySite (method: Sitecore.Configuration.DefaultFactory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)).]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +539
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +125 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +731

我已经测试了提供的代码,您收到此错误的主要原因是程序集 Mysite 不在 bin 文件夹中。

  1. 确保 MySite.dll 已复制到 bin 文件夹。
  2. 命名空间MySite.Web.Pipelines.RegisterPlatformBundles, MySite有效