无法使System.Web.Optimization与Nancy Self Hosting一起运行

Can't get System.Web.Optimization to run with Nancy Self Hosting
2021-03-07
  •  译文(汉语)
  •  原文(英语)

使用Nancy Self Hosting使用System.Web.Optimization的人有运气吗?如果我注释掉"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 ....
速聊1:
岂不是@Styles.Render("~/csspack/logincss")没有@Html.Raw或没有ToString()?
速聊2:
您遗漏了最重要的信息-您得到的错误
速聊3:
如果您在Asp.net中工作,是的,但是在Nancy中您必须添加它.
速聊4:
我添加了我的错误或缺乏.
速聊5:
.我有同样的问题,找到解决办法还算幸运吗?
解决过程1

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

毫无问题地工作了.其实并没有太大的改变.看起来System.Web.Optimization从Cassette借来了很多东西.


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

速聊1:
好的,我也无法运行它,可能与Squish或Cassette一起使用了,谢谢!

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 ....
Talk1:
Shouldn't it be just @Styles.Render("~/csspack/logincss") without @Html.Raw or ToString() ?
Talk2:
You left out the most important information - the error you get
Talk3:
If you were working in Asp.net yes but in Nancy you have to add that.
Talk4:
I added my error or lack there of.
Talk5:
. I have the same problem, any luck with finding a solution yet?
Solutions1

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

Talk1:
Ok I have not been able to get it running either, probably with go with Squish or Cassette, thanks!
转载于:https://stackoverflow.com/questions/23003482/cant-get-system-web-optimization-to-run-with-nancy-self-hosting

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入