UrlHelperExtensionsIdenticon Method (IUrlHelper, Identicon, Int32, ExportImageFormat)

Generates an URL to an identicon.
public static string Identicon(
	this IUrlHelper helper,
	Identicon icon,
	int size = 0,
	ExportImageFormat format = ExportImageFormat.Png
)

Parameters

helperIUrlHelper
The IUrlHelper.
iconJdenticonIdenticon
The icon that will be rendered.
sizeSystemInt32 (Optional)
The size of the generated icon in pixels. If no size is specified the size of icon will be used.
formatJdenticonExportImageFormat (Optional)
The file format of the generated icon.

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 or icon 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