-
Notifications
You must be signed in to change notification settings - Fork 0
Adding a custom favicon
By default, Nancy will use an icon of the Nancy logo as the favicon for any Nancy application, unless you provide you own. Overriding this behavior to provide your own custom icon is very simple
Simply place a .ico or .png file, called favicon anywhere in your application path (to learn more about the application root path, please consult the The Root Path section) and Nancy will recursively scan your application, at start up, for the file.
If you have more then one favicon in your application, the first one it finds will be used.
You can also embed a favicon in your application assembly. To make Nancy use the embedded icon, simply override the FavIcon property of your bootstrapper, and add the following code:
public class Bootstrapper : DefaultNancyBootstrapper
{
private byte[] favicon;
protected override byte[] FavIcon
{
get { return this.favicon?? (this.favicon= LoadFavIcon()); }
}
private byte[] LoadFavIcon()
{
//TODO: remember to replace 'AssemblyName' with the prefix of the resource
using (var resourceStream = GetType().Assembly.GetManifestResourceStream("AssemblyName.favicon.ico"))
{
var tempFavicon = new byte[resourceStream.Length];
resourceStream.Read(tempFavicon, 0, (int)resourceStream.Length);
return tempFavicon;
}
}
}If you do not wish to use a favicon at all, then simply override the FavIcon property on your Bootstrapper and return null.
Note that returning null will result in requests for /favicon.ico being passed along the pipeline, which means (in particular) that your modules may see this request.
Try:
- Clearing your browser's cache.
- Navigating to
http://site/favicon.icoand forcing a refresh (usually Ctrl+F5).
<< Part 13. Diagnostics - Documentation overview - [Part 15. The Application Before, After and OnError pipelines >>](The Application Before, After and OnError pipelines)
- Taking a look at the DynamicDictionary
- The before and after module hooks
- Model binding
- Bootstrapper
- View Engines
- View location conventions
- Testing your application
- The root path
- Managing static content
- Diagnostics
- Adding a custom FavIcon
- The Application Before, After and OnError pipelines
- Generating a custom error page
- The cryptography helpers
- Content negotiation
- Authentication
- More to come
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Blog Posts, Video & Audio
- Async-Beta (Async Beta)