Class WebHelper
Misc ASP.NET related helper methods.
Namespace: Neon.Web
Assembly: Neon.Web.dll
Syntax
public static class WebHelper
Methods
AddNeon(IMvcBuilder, bool, Func<Type, bool>, bool)
Performs Neon related initialization including adding the the RoundTripJsonInputFormatter, RoundTripJsonOutputFormatter and Newtonsoft JSON formatters to the request pipeline. These handle serialization and deserailzation of JSON text submitted to and returned from web services and classes generated by Neon.ModelGen implementing IRoundtripData as well as many basic .NET types.
By default, this also adds an exception filter to the ASP.NET middleware that logs any uncaught exceptions and handles exception response formatting.
Declaration
public static IMvcBuilder AddNeon(this IMvcBuilder builder, bool disableRoundTripFormatters = false, Func<Type, bool> allowRoundtripFormatter = null, bool disableExceptionFilter = false)
Parameters
Type | Name | Description |
---|---|---|
IMvcBuilder | builder | The MVC builder. |
bool | disableRoundTripFormatters | Optionally disable adding the round-trip formatters. |
Func<Type, bool> | allowRoundtripFormatter | Optional lamda function that can be used to customize which types allowed
to be handled by the custom round-trip formatters. When this is |
bool | disableExceptionFilter | Optionally disables the addition of the built-in exception filter middleware (see remarks). |
Returns
Type | Description |
---|---|
IMvcBuilder | The |
Remarks
This provides both backwards and forwards data compatibility on both the client and service side by retaining object properties that one side or the other doesn't know about. This enables scenarios where new properties are added to a data object but the solution components aren't all upgraded at the same time as a monolithic app.
By default, this method adds a an exception filter to the MVC middleware pipeline. This filter handles ArgumentException, ArgumentNullException, and HttpApiException exceptions by having ASP.NET return a BadRequest for the argument exceptions and the status code and error code (reason phrase) from the HttpApiException.
This combined with the Requires(bool, string, string, HttpStatusCode), Requires(Func<bool>, string, string, HttpStatusCode), Requires(bool, string, string, HttpStatusCode) and Requires(Func<bool>, string, string, HttpStatusCode) methods help make it easier for REST methods to check input parameters as well as transmit additional details back to the calling client.
GetUri(HttpRequest)
Returns the full URI for an HttpRequest (not including the port number).
Declaration
public static string GetUri(this HttpRequest request)
Parameters
Type | Name | Description |
---|---|---|
HttpRequest | request | The request. |
Returns
Type | Description |
---|---|
string | The fully qualified URI including any query parameters. |