【问题标题】:Can't get System.Web.Optimization to run with Nancy Self Hosting无法使用 Nancy Self Hosting 运行 System.Web.Optimization
【发布时间】:2014-05-25 01:42:46
【问题描述】:

有没有人在使用 System.Web.Optimization 和 Nancy Self Hosting 时运气好? 如果我注释掉 "Styles.Render("~/csspack/logincss").ToString()" 视图工作正常。 如果我将其留在空白页面中,则会发送到浏览器。

这就是我的 Razor 配置的样子。

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; }
    }
}

我是这样在启动时注册的。

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

            container.Register<RazorViewEngine>();

          .....bundle code...
}

这是我的看法。

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 ....

【问题讨论】:

  • 不应该只是@Styles.Render("~/csspack/logincss") 没有@Html.RawToString() 吗?
  • 您遗漏了最重要的信息 - 您得到的错误
  • @ArtyomNeustroev 如果你在 Asp.net 工作,是的,但在 Nancy 你必须添加。
  • @TheCodeJunkie 我添加了我的错误或缺少。
  • @DonnyV。我有同样的问题,有没有找到解决方案的运气?

标签: c# razor nancy


【解决方案1】:

我无法让它工作,所以我最终切换到了 Cassette。 http://getcassette.net/

直接在门口工作,没有任何问题。真的不必 变化很大。看起来 System.Web.Optimization 借鉴了很多 Cassette。

更新
在 Linux 上运行时,Cassette 给我带来了奇怪的性能问题和错误。 我最终只是建立了自己的。 https://github.com/donnyv/Nancy.BundleIt

【讨论】:

  • 好的,我也无法运行它,可能是与 Squish 或 Cassette 一起运行,谢谢!
猜你喜欢
  • 2016-09-20
  • 2011-11-03
  • 1970-01-01
  • 1970-01-01
  • 2012-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多