UrlHelperExtensionsIdenticon Method (IUrlHelper, Object, Int32, ExportImageFormat, IdenticonStyle)

Generates an URL to an identicon.
public static string Identicon(
	this IUrlHelper helper,
	Object value,
	int size,
	ExportImageFormat format = ExportImageFormat.Png,
	IdenticonStyle style = null
)

Parameters

helperIUrlHelper
The IUrlHelper.
valueSystemObject
The value that will be hashed and used as base for the icon.
sizeSystemInt32
The size of the generated icon in pixels.
formatJdenticonExportImageFormat (Optional)
The file format of the generated icon.
styleJdenticonIdenticonStyle (Optional)
The icon style.

Return Value

String

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IUrlHelper. 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.
ArgumentNullExceptionhelper was null.

Remarks

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.

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

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

Examples

This example shows how to use the IUrlHelper extension methods to generate identicon urls.

HtmlHelper approach
@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>

See Also

Reference