Crowdhandler.MVCSDK 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Crowdhandler.MVCSDK --version 1.0.0
NuGet\Install-Package Crowdhandler.MVCSDK -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Crowdhandler.MVCSDK" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Crowdhandler.MVCSDK --version 1.0.0
#r "nuget: Crowdhandler.MVCSDK, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Crowdhandler.MVCSDK as a Cake Addin
#addin nuget:?package=Crowdhandler.MVCSDK&version=1.0.0

// Install Crowdhandler.MVCSDK as a Cake Tool
#tool nuget:?package=Crowdhandler.MVCSDK&version=1.0.0

Crowdhandler MVC .NET SDK

Protect your .NET MVC Applications with Crowdhandler.

Nuget Package [Github](<RepositoryUrl>https://github.com/Crowdhandler/crowdhandler-dotnet-integration</RepositoryUrl>)

Getting Started

1) Add Reference to your project

This is easist done using NuGet, find the Crowdhandler.MVCSDK package in the NuGet package manager, or via the dotnet CLI

dotnet add package Crowdhandler.MVCSDK

2) Add your Crowdhandler API settings

Web.config

<appSettings>
    <add key="CROWDHANDLER_PUBLIC_KEY" value="YOUR_PUBLIC_KEY" />
    <add key="CROWDHANDLER_PRIVATE_KEY" value="YOUR_PRIVATE_KEY" />
    <add key="CROWDHANDLER_API_ENDPOINT" value="http://api.crowdhandler.com" />
    <add key="CROWDHANDLER_WR_ENDPOINT" value="https://wait.crowdhandler.com"/>
</appSettings>

Your API keys can found in your Crowdhandler dashboard. Click here for more information

3) Apply the Crowdhandler Filter Attribute to your Controller Actions

ExampleTicketingController.cs

using Crowdhandler.MVCSDK;

namespace MyTicketingApp.Controllers
{
    public class TicketingController : Controller
    {
        [CrowdhandlerFilter]
        public ActionResult Index()
        {
            return View();
        }
    }
}

4) Configure the CrowdhandlerFilter Attribute

The default CrowdhandlerFilterAttribute properties should work in most environments, but if neccessary, custom behaviour can be configured with the following:

ApiEndpoint, PrivateApiKey & PublicApiKey (string) (default null)

These API configuration options can be directly injected into the Action Filter, bypassing their default configuration options, which are pulled from Web.Config. For more information see the Configuration section below

FailTrust (boolean) (default true)

If false, a user that fails to check-in with CrowdHandler's API will be sent to a safety net waiting room until CrowdHandler is able to make a decision on what to do with them. In this option false you may also want to set the CROWDHANDLER_SAFETYNET_SLUG setting (see Configuration section)

If true, users that fail to check-in with CrowdHandler's API will be trusted

Read more about Trust on Fail

GatekeeperType (Type implementing IGateKeeper) (default null)

If set, this Class of GateKeeper will be used instead of the default when validating users. Used to implement custom behavior in the GateKeeper validation process.

Configuration

The following can be configured in the appSettings property of your applications Web.config file

Value Description Required
CROWDHANDLER_PUBLIC_KEY Your Crowdhandler public API key. Yes
CROWDHANDLER_PRIVATE_KEY Your Crowdhandler private API key. Yes
CROWDHANDLER_API_ENDPOINT The Crowdhandler API URL Yes
CROWDHANDLER_WR_ENDPOINT Your Crowdhandler waiting room URL Yes
CROWDHANDLER_API_REQUEST_TIMEOUT How many seconds to wait for the Crowdhandler API to respond before failing. Default: 3 No
CROWDHANDLER_ROOM_CACHE_TIME How many seconds to cache your Crowdhandler room configuration for. Set the value to 0 to never cache. Default: 60 No
CROWDHANDLER_SAFETYNET_SLUG If failTrust is set to false, this waiting room slug will be used as the safety net room No

Customisation

I only need to validate certain urls on my Controller Action

If you need finer control from the Action Filter, for example you'd like to exclude some urls from validation, you can extend the CrowdhandlerFilterAttribute class, implement your own url filtering logic, and then execute it. For example:

MyCustomLogicFilterAttribute.cs

public class MyCustomLogicFilterAttribute : CrowdhandlerFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var url = filterContext.HttpContext.Request.Url;

        // do not attempt to validate the json events feed
        if (url.AbsolutePath.StartsWith("/events/feed"))
        {
            // return to controller
            return;
        }

        // Run validation
        base.OnActionExecuting(filterContext);
    }
}

Then update your controller to use this new Filter Attribute

ExampleTicketingController.cs

public class TicketingController : Controller
{
    [MyCustomLogicFilter]
    public ActionResult Index()
    {
        return View();
    }
}

I want to store my Room Configuration locally

By default the Crowdhandler room configuration is fetched via the API and then cached in memory for 1 minute. If you would like to bypass this and keep static copy of the Configuation locally, you can do this by implementing/extending your own IGateKeeper class, and passing it's type to the GatekeeperType property of the CrowdhandlerFilterAttribute. For example:

MyCustomGateKeeper.cs

using Crowdhandler.NETsdk;
using Crowdhandler.NETsdk.JSONTypes;
using Newtonsoft.Json;

public class MyCustomGateKeeper : GateKeeper
{
    public override List<RoomConfig> getRoomConfig()
    {
        return JsonConvert.DeserializeObject<List<RoomConfig>>(System.IO.File.ReadAllText(@"path_to_roomconfig.json"));
    }
}

ExampleTicketingController.cs

public class TicketingController : Controller
{
    [CrowdhandlerFilter(GatekeeperType = typeof(MyCustomGateKeeper))]
    public ActionResult Index()
    {
        return View();
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9 167 1/4/2024
1.0.7 148 7/4/2023
1.0.6 131 7/2/2023
1.0.5 226 2/9/2023
1.0.4 234 2/7/2023
1.0.3 248 2/1/2023
1.0.2 284 12/9/2022
1.0.1 279 12/6/2022
1.0.0 306 10/17/2022