Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class CustomNancyBootstraper : DefaultNancyBootstrapper
{
protected override void ConfigureConventions(NancyConventions nancyConventions)
{
nancyConventions.StaticContentsConventions.Clear();
nancyConventions.StaticContentsConventions.Add(Css);
base.ConfigureConventions(nancyConventions);
}
private Response Css(NancyContext context, string s)
{
const string resourcePath = "/Content";
var path = context.Request.Url.Path;
if (!path.StartsWith(resourcePath, StringComparison.InvariantCultureIgnoreCase)) return null;
return new EmbeddedFileResponse(GetType().Assembly, "Site.Content", Path.GetFileName(context.Request.Url.Path));
}
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
var assembly = GetType().Assembly;
ResourceViewLocationProvider.RootNamespaces.Clear();
ResourceViewLocationProvider.RootNamespaces.Add(assembly, "Site.Views");
base.ConfigureApplicationContainer(container);
}
protected override NancyInternalConfiguration InternalConfiguration
{
get
{
return NancyInternalConfiguration.WithOverrides(config => { config.ViewLocationProvider = typeof(ResourceViewLocationProvider); });
}
}
private byte[] _favicon;
protected override byte[] FavIcon
{
get { return _favicon ?? (this._favicon = LoadFavIcon()); }
}
private byte[] LoadFavIcon()
{
using (var resourceStream = GetType().Assembly.GetManifestResourceStream("Site.favicon.ico"))
{
var tempFavicon = new byte[resourceStream.Length];
resourceStream.Read(tempFavicon, 0, (int)resourceStream.Length);
return tempFavicon;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.