HtmlHelperExtensionsIdenticon Method (IHtmlHelper, Byte, Int32, String, ExportImageFormat, IdenticonStyle)

Renders an identicon as an IMG tag.
public static IHtmlContent Identicon(
	this IHtmlHelper helper,
	byte[] hash,
	int size,
	string alt = null,
	ExportImageFormat format = ExportImageFormat.Png,
	IdenticonStyle style = null
)

Parameters

helperIHtmlHelper
The IHtmlHelper.
hashSystemByte
The hash that will be used as base for the icon. Must contain at least 6 bytes.
sizeSystemInt32
The size of the generated icon in pixels.
altSystemString (Optional)
The alt attribute of the rendered image.
formatJdenticonExportImageFormat (Optional)
The file format of the generated icon.
styleJdenticonIdenticonStyle (Optional)
The icon style.

Return Value

IHtmlContent

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IHtmlHelper. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ExceptionCondition
ArgumentOutOfRangeExceptionsize was less than 1.
ArgumentExceptionhash was too short.
ArgumentNullExceptionhelper or hash was null.

Remarks

This extension method can be used in views to insert identicons as <img> tags. The <img> tag will include an url that will be handled by the Jdenticon middleware. Insert a call to UseJdenticon(IApplicationBuilder) right above UseStaticFiles(IApplicationBuilder) to enable the Jdenticon middleware.

Startup.cs
public class Startup
{
    /* ... */

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        /* ... */
        app.UseJdenticon();
        app.UseStaticFiles();
        app.UseMvc();
        /* ... */
    }
}

If you don't need a whole IMG tag, but rather just an url, please have a look at UrlHelperExtensions.

Examples

This example shows how to use the IHtmlHelper extension methods to render identicons as IMG tags.

IHtmlHelper approach
@using Jdenticon.AspNet.Mvc;

<!-- The following markup -->

<div class="user-info">
    @Html.Identicon("JohnDoe64", 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>

See Also

Reference