简体   繁体   中英

Can't get System.Web.Optimization to run with Nancy Self Hosting

Has anyone had any luck using System.Web.Optimization with Nancy Self Hosting? If I comment out "Styles.Render("~/csspack/logincss").ToString()" the view works fine. If I leave it in a blank page is sent to the browser.

This is what my Razor config looks like.

public class RazorConfig : IRazorConfiguration
{
    public IEnumerable<string> GetAssemblyNames()
    {
        yield return "Microsoft.Web.Infrastructure";
        yield return "WebGrease";
        yield return "System.Web.Optimization";
        yield return "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
    }

    public IEnumerable<string> GetDefaultNamespaces()
    {
        yield return "Microsoft.Web.Infrastructure";
        yield return "WebGrease";
        yield return "System";
        yield return "System.Web";
        yield return "System.Web.Optimization";
        yield return "Nancy.ViewEngines.Razor";
    }

    public bool AutoIncludeModelNamespace
    {
        get { return false; }
    }
}

I registered it in startup like this.

protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
            container.Register<IRazorConfiguration, RazorConfig>().AsSingleton();

            container.Register<RazorViewEngine>();

          .....bundle code...
}

This is my view.

inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@using Nancy.Helpers
@using System.Web.Optimization

<!DOCTYPE html>
<html lang="en">
<head>
<head>
    <meta charset="utf-8" />
    <title>Log In</title>
    @Html.Raw(Styles.Render("~/csspack/logincss").ToString())
</head>
.... more html ....

I couldn't get this to work, so I ended up switching to Cassette. http://getcassette.net/

Worked right out of the gate with no issues. Didn't really have to change much. Looks like System.Web.Optimization borrowed a lot from Cassette.

Update
Cassette was giving me weird performance issues and errors when running on Linux. I ended up just building my own. https://github.com/donnyv/Nancy.BundleIt

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM