NancyFx不会显示图像

时间:2014-07-30 20:29:30

标签: nancy

我的最后一次尝试:甚至不知道我在做什么:

Get["/{any}/x.png"] = x => {
    return Response.AsImage(Program.portal.ourRoot + "x.png");
};

Get["/{any}/{moreany}/x.png"] = x => {
    return Response.AsImage(Program.portal.ourRoot + "x.png");
};

Get["/{any}/{moreany}/{extraany}/x.png"] = x => {
    return Response.AsImage(Program.portal.ourRoot + "x.png");
};

我目前在ConfigureConvetions中的内容(在BootStrapper中)。到目前为止,我已尝试了很多排列。

protected override void ConfigureConventions(NancyConventions conventions) {
    //conventions.StaticContentsConventions.AddFile("x.png", ourRoot + "x.png");
    conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddFile("/portal/images/x.png", ourRoot + "x.png"));
    conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("images", ourRoot, new string[] { "png" }));
    conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/portal/", ourRoot, new string[] { "png" }));
    conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/", ourRoot, new string[] { "png" }));
    base.ConfigureConventions(conventions);
}

我有一个指向ourRoot的CustomRootPathProvider(字符串,当前包含直接C:\ somepathstuffhere \到内容目录)。

我只需要为我的需求提供单个图像(至少,现在,事情总是趋于增长)。我使用目录结构作为变量,因此我需要能够从非常多的位置提供此图像。

我的根文件夹中有一个图像副本,并且在一个名为images的目录中("图像"已经有了' /'' ,偶尔甚至通过中间)。我目前正在使用" /images/x.png"来引用该图像,但我已尝试从根,只是名称和" images / x.png"。

谢谢!

如果我弄明白的话,我会在同一时间回复(我假设它非常简单。)

解决:解决了? \非最佳

我将/images/x.png引用更改为' x.png',然后我将扩展引用删除到以下行。

conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("/", ourRoot));
南希开始追捕' x.png'根页面和\ Portal \页面的图像。然后第二个Get /{any}/{moreany}/x.png开始捕捉其余的' x.png'请求(\ Portal \ Project)。

我真的不确定,为什么它突然开始工作。我一直在玩排列游戏。

大的非最佳部分,是每个目录的图像版本被视为全新的。如果有人能为我解决这个问题,那就太好了。如果我想弄清楚自己要做些什么,我会用我的解决方案回复。

解决

这个解决方案对任何熟悉网络编程的人都不感兴趣。它更像是一个新用户陷阱的情况。当我开始设置NancyFX时,我非常彻底地阅读了文档(即使我在第一次阅读时没有完成所有操作)。当我到达web.config部分时,我首先检查了VS中的解决方案资源管理器,但我没有看到它。所以我刚进入我的项目目录并且创建了一个(并且存在问题)。我制作的那个从未对项目应用过设置。

我认为这是一个概念错误,我只是不了解,知道在哪里看。\

为社区提供帮助!希望我的经验可以帮助其他第一时间的用户。

0 个答案:

没有答案
相关问题