public static string Identicon( this IUrlHelper helper, Identicon icon, int size = 0, ExportImageFormat format = ExportImageFormat.Png )
Exception | Condition |
---|---|
ArgumentOutOfRangeException | size was less than 1. |
ArgumentNullException | helper or icon was null. |
This extension method can be used in views to generate urls to identicons, which are handled by the Jdenticon middleware. Insert a call to UseJdenticon(IApplicationBuilder) right above UseStaticFiles(IApplicationBuilder) to enable the Jdenticon middleware.
public class Startup { /* ... */ public void Configure(IApplicationBuilder app, IHostingEnvironment env) { /* ... */ app.UseJdenticon(); app.UseStaticFiles(); app.UseMvc(); /* ... */ } }
This example shows how to use the IUrlHelper extension methods to generate identicon urls.
@using Jdenticon.AspNetCore; <!-- The following markup --> <div class="user-info"> <img src="@Url.Identicon("JohnDoe64", 60)" width="60" height="60" alt="JohnDoe64 icon" > <div class="user-info__name">JohnDoe64</div> </div> <!-- is rendered as --> <div class="user-info"> <img src="/identicons/5AMA8Xyneag78XyneQ--" width="60" height="60" alt="JohnDoe64 icon" /> <div class="user-info__name">JohnDoe64</div> </div>