Moesif.Middleware
1.3.25
See the version list below for details.
dotnet add package Moesif.Middleware --version 1.3.25
NuGet\Install-Package Moesif.Middleware -Version 1.3.25
<PackageReference Include="Moesif.Middleware" Version="1.3.25" />
paket add Moesif.Middleware --version 1.3.25
#r "nuget: Moesif.Middleware, 1.3.25"
// Install Moesif.Middleware as a Cake Addin #addin nuget:?package=Moesif.Middleware&version=1.3.25 // Install Moesif.Middleware as a Cake Tool #tool nuget:?package=Moesif.Middleware&version=1.3.25
Moesif Middleware for .NET
Middleware SDK that captures incoming or outgoing API calls from .NET apps and sends to Moesif API Analytics.
How to install
Install the Nuget Package:
Install-Package Moesif.Middleware
Jump to installation for your specific framework:
Net Core installation
The below installation is intended for .NET 5 or .NET Core 2.1 and higher. For .NET Framework, go to .NET Framework installation.
In Startup.cs
file in your project directory, please add app.UseMiddleware<MoesifMiddleware>(moesifOptions);
to the pipeline.
To collect the most context, it is recommended to add the middleware after other middleware such as SessionMiddleware and AuthenticationMiddleware.
Add the middleware to your application:
using Moesif.Middleware;
public class Startup {
// moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
Dictionary<string, object> moesifOptions = new Dictionary<string, object>
{
{"ApplicationId", "Your Moesif Application Id"},
{"LogBody", true},
...
# For other options see below.
};
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMiddleware<MoesifMiddleware>(moesifOptions);
app.UseMvc();
}
}
Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top-right menu, and then clicking Installation.
.NET Core example
Checkout the examples using .NET Core 2.0 and .NET Core 3.0
.NET Core options
ApplicationId
(required), string, is obtained via your Moesif Account, this is required.
Skip
(optional) (HttpRequest, HttpResponse) ⇒ boolean, a function that takes a request and a response, and returns true if you want to skip this particular event.
IdentifyUser
(optional) (HttpRequest, HttpResponse) ⇒ string, a function that takes a request and a response, and returns a string that is the user id used by your system. While Moesif identify users automatically, if your set up is very different from the standard implementations, it would be helpful to provide this function.
IdentifyCompany
(optional) (HttpRequest, HttpResponse) ⇒ string, a function that takes a request and a response, and returns a string that is the company id for this event.
GetSessionToken
(optional) (HttpRequest, HttpResponse) ⇒ string, a function that takes a request and a response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.
GetMetadata
(optional) (HttpRequest, HttpResponse) ⇒ dictionary, getMetadata is a function that returns an object that allows you to add custom metadata that will be associated with the event. The metadata must be a dictionary that can be converted to JSON. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.
MaskEventModel
(optional) (EventModel) ⇒ EventModel, a function that takes an EventModel and returns an EventModel with desired data removed. Use this if you prefer to write your own mask function. The return value must be a valid EventModel required by Moesif data ingestion API. For details regarding EventModel please see the Moesif CSharp API Documentation.
public static Func<EventModel, EventModel> MaskEventModel = (EventModel moesifEvent) =>
{
Dictionary<String, String> eventRequestHeaders = moesifEvent.Request.Headers;
bool keyExists = eventRequestHeaders.ContainsKey("Authorization");
if (keyExists)
{
eventRequestHeaders.Remove("Authorization");
};
return moesifEvent;
};
ApiVersion
(optional), string, API version associated with this particular event.
LocalDebug
boolean, set to true to print internal log messages for debugging SDK integration issues.
LogBody
boolean, default true. Set to false to not log the request and response body to Moesif.
AuthorizationHeaderName
(optional), string, Request header containing a Bearer or Basic token to extract user id. Also, supports a comma-separated string. We will check headers in order like "X-Api-Key,Authorization".
AuthorizationUserIdField
(optional), string, Field name in JWT/OpenId token's payload for identifying users. Only applicable if authorization_header_name is set and is a Bearer token.
Capture_Outgoing_Requests
(optional), Set to capture all outgoing API calls from your app to third parties like Stripe or to your own dependencies while using System.Net.Http package. The options below is applied to outgoing API calls. When the request is outgoing, for options functions that take request and response as input arguments, the request and response objects passed in are HttpRequestMessage request and HttpResponseMessage response objects.
How to configure your application to start capturing outgoing API calls.
using System.Net.Http;
using Moesif.Middleware.Helpers;
// moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
MoesifCaptureOutgoingRequestHandler handler = new MoesifCaptureOutgoingRequestHandler(new HttpClientHandler(), moesifOptions);
HttpClient client = new HttpClient(handler);
GetMetadataOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ dictionary, getMetadata is a function that returns an object that allows you to add custom metadata that will be associated with the event. The metadata must be a dictionary that can be converted to JSON. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.
GetSessionTokenOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ string, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.
IdentifyUserOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ string, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns a string that is the user id used by your system. While Moesif identify users automatically, if your set up is very different from the standard implementations, it would be helpful to provide this function.
IdentifyCompanyOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ string, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns a string that is the company id for this event.
SkipOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ boolean, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns true if you want to skip this particular event.
MaskEventModelOutgoing
(optional) (EventModel) ⇒ EventModel, a function that takes an EventModel and returns an EventModel with desired data removed. Use this if you prefer to write your own mask function. The return value must be a valid EventModel required by Moesif data ingestion API. For details regarding EventModel please see the Moesif CSharp API Documentation.
LogBodyOutgoing
boolean, default true. Set to false to not log the request and response body to Moesif.
Example configuration:
public static Func<HttpRequest, HttpResponse, string> IdentifyUser = (HttpRequest req, HttpResponse res) => {
// Implement your custom logic to return user id
return req.HttpContext?.User?.Identity?.Name;
};
public static Func<HttpRequest, HttpResponse, string> IdentifyCompany = (HttpRequest req, HttpResponse res) => {
return req.Headers["X-Organization-Id"];
};
public static Func<HttpRequest, HttpResponse, string> GetSessionToken = (HttpRequest req, HttpResponse res) => {
return req.Headers["Authorization"];
};
public static Func<HttpRequest, HttpResponse, Dictionary<string, object>> GetMetadata = (HttpRequest req, HttpResponse res) => {
Dictionary<string, object> metadata = new Dictionary<string, object>
{
{"string_field", "value_1"},
{"number_field", 0},
{"object_field", new Dictionary<string, string> {
{"field_a", "value_a"},
{"field_b", "value_b"}
}
}
};
return metadata;
};
static public Dictionary<string, object> moesifOptions = new Dictionary<string, object>
{
{"ApplicationId", "Your Moesif Application Id"},
{"ApiVersion", "1.1.0"},
{"IdentifyUser", IdentifyUser},
{"IdentifyCompany", IdentifyCompany},
{"GetSessionToken", GetSessionToken},
{"GetMetadata", GetMetadata}
};
NET Framework installation
The below installation is intended for .NET Framework 4.5 and higher. For .NET 5 or .NET 2.1 and higher, go to .Net Core / .NET 5 installation.
In Startup.cs
file in your project directory, please add app.Use<MoesifMiddleware>(moesifOptions);
to the pipeline.
To collect the most context, it is recommended to add the middleware after other middleware such as SessionMiddleware and AuthenticationMiddleware.
If your app uses Windows Communication Foundation (WCF), set DisableStreamOverride to true
Add the middleware to your application:
using Moesif.Middleware;
public class Startup {
// moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
Dictionary<string, object> moesifOptions = new Dictionary<string, object>
{
{"ApplicationId", "Your Moesif Application Id"},
{"LogBody", true},
...
# For other options see below.
};
public void Configuration(IAppBuilder app)
{
app.Use<MoesifMiddleware>(moesifOptions);
}
}
Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top-right menu, and then clicking Installation.
Add OWIN dependencies
IIS integrated pipeline
If you're running your .NET app on IIS (or Visual Studio IIS Express) using integrated mode (most common), you will have to install the OWIN SystemWeb package if not done so already: Review OWIN Middleware in the IIS integrated pipeline for more info.
Install-Package Microsoft.Owin.Host.SystemWeb
Moesif does not support IIS running in Classic mode (Backwards compatibility for IIS 6.0). Unless your app predates IIS 6.0 and requires classic mode, you should switch to integrated mode.
{: .notice--primary}
Self-Host executable
While uncommon, if your application is a self-hosted executable that does not run on IIS, you may have to install the SelfHost package if not done so already:
For .NET Web API applications:
Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
For all other .NET applications:
Install-Package Microsoft.Owin.SelfHost -Pre
.NET Framework Examples
The following examples are available for .NET Framework with Moesif:
- .NET Framework Example using .NET Framework 4.6.1 and IIS
- .NET Framework SelfHost Example using .NET Framework 4.6.1 (SelfHost is uncommon)
.NET Framework options
The request and response objects passed in are IOwinRequest request and IOwinResponse response objects.
ApplicationId
(required), string, is obtained via your Moesif Account, this is required.
Skip
(optional) (IOwinRequest, IOwinResponse) ⇒ boolean, a function that takes a request and a response, and returns true if you want to skip this particular event.
IdentifyUser
(optional) (IOwinRequest, IOwinResponse) ⇒ string, a function that takes a request and a response, and returns a string that is the user id used by your system. While Moesif identify users automatically, if your set up is very different from the standard implementations, it would be helpful to provide this function.
IdentifyCompany
(optional) (IOwinRequest, IOwinResponse) ⇒ string, a function that takes a request and a response, and returns a string that is the company id for this event.
GetSessionToken
(optional) (IOwinRequest, IOwinResponse) ⇒ string, a function that takes a request and a response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.
GetMetadata
(optional) (IOwinRequest, IOwinResponse) ⇒ dictionary, getMetadata is a function that returns an object that allows you to add custom metadata that will be associated with the event. The metadata must be a dictionary that can be converted to JSON. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.
MaskEventModel
(optional) (EventModel) ⇒ EventModel, a function that takes an EventModel and returns an EventModel with desired data removed. Use this if you prefer to write your own mask function. The return value must be a valid EventModel required by Moesif data ingestion API. For details regarding EventModel please see the Moesif CSharp API Documentation.
public static Func<EventModel, EventModel> MaskEventModel = (EventModel moesifEvent) =>
{
Dictionary<String, String> eventRequestHeaders = moesifEvent.Request.Headers;
bool keyExists = eventRequestHeaders.ContainsKey("Authorization");
if (keyExists)
{
eventRequestHeaders.Remove("Authorization");
};
return moesifEvent;
};
ApiVersion
(optional), string, api version associated with this particular event.
LocalDebug
boolean, set to true to print internal log messages for debugging SDK integration issues.
LogBody
boolean, default true. Set to false to not log the request and response body to Moesif.
DisableStreamOverride
boolean, Set to true to disable overriding the request body stream. This is required if your app is using Windows Communication Foundation (WCF). Otherwise, you may experience issues when your business logic accesses the request body.
AuthorizationHeaderName
(optional), string, Request header containing a Bearer or Basic token to extract user id. Also, supports a comma separated string. We will check headers in order like "X-Api-Key,Authorization".
AuthorizationUserIdField
(optional), string, Field name in JWT/OpenId token's payload for identifying users. Only applicable if authorization_header_name is set and is a Bearer token.
Capture_Outgoing_Requests
(optional), Set to capture all outgoing API calls from your app to third parties like Stripe or to your own dependencies while using System.Net.Http package. The options below is applied to outgoing API calls. When the request is outgoing, for options functions that take request and response as input arguments, the request and response objects passed in are HttpRequestMessage request and HttpResponseMessage response objects.
How to configure your application to start capturing outgoing API calls.
using System.Net.Http;
using Moesif.Middleware.Helpers;
// moesifOptions is an object of type Dictionary<string, object> which holds configuration options for your application.
MoesifCaptureOutgoingRequestHandler handler = new MoesifCaptureOutgoingRequestHandler(new HttpClientHandler(), moesifOptions);
HttpClient client = new HttpClient(handler);
GetMetadataOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ dictionary, getMetadata is a function that returns an object that allows you to add custom metadata that will be associated with the event. The metadata must be a dictionary that can be converted to JSON. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.
GetSessionTokenOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ string, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.
IdentifyUserOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ string, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns a string that is the user id used by your system. While Moesif identify users automatically, if your set up is very different from the standard implementations, it would be helpful to provide this function.
IdentifyCompanyOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ string, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns a string that is the company id for this event.
SkipOutgoing
(optional) (HttpRequestMessage, HttpResponseMessage) ⇒ boolean, a function that takes a HttpRequestMessage and a HttpResponseMessage, and returns true if you want to skip this particular event.
MaskEventModelOutgoing
(optional) (EventModel) ⇒ EventModel, a function that takes an EventModel and returns an EventModel with desired data removed. Use this if you prefer to write your own mask function. The return value must be a valid EventModel required by Moesif data ingestion API. For details regarding EventModel please see the Moesif CSharp API Documentation.
LogBodyOutgoing
boolean, default true. Set to false to not log the request and response body to Moesif.
Example Configuration:
public static Func<IOwinRequest, IOwinResponse, string> IdentifyUser = (IOwinRequest req, IOwinResponse res) => {
// Implement your custom logic to return user id
return req?.Context?.Authentication?.User?.Identity?.Name;
};
public static Func<IOwinRequest, IOwinResponse, string> IdentifyCompany = (IOwinRequest req, IOwinResponse res) => {
return req.Headers["X-Organization-Id"];
};
public static Func<IOwinRequest, IOwinResponse, string> GetSessionToken = (IOwinRequest req, IOwinResponse res) => {
return req.Headers["Authorization"];
};
public static Func<IOwinRequest, IOwinResponse, Dictionary<string, object>> GetMetadata = (IOwinRequest req, IOwinResponse res) => {
Dictionary<string, object> metadata = new Dictionary<string, object>
{
{"string_field", "value_1"},
{"number_field", 0},
{"object_field", new Dictionary<string, string> {
{"field_a", "value_a"},
{"field_b", "value_b"}
}
}
};
return metadata;
};
static public Dictionary<string, object> moesifOptions = new Dictionary<string, object>
{
{"ApplicationId", "Your Moesif Application Id"},
{"LocalDebug", true},
{"LogBody", true},
{"LogBodyOutgoing", true},
{"ApiVersion", "1.1.0"},
{"IdentifyUser", IdentifyUser},
{"IdentifyCompany", IdentifyCompany},
{"GetSessionToken", GetSessionToken},
{"GetMetadata", GetMetadata},
{"BatchSize", 25}
};
Update a Single User
Create or update a user profile in Moesif.
The metadata field can be any customer demographic or other info you want to store.
Only the user_id
field is required.
For details, visit the C# API Reference.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#users for campaign schema
Dictionary<string, object> campaign = new Dictionary<string, object>
{
{"utm_source", "google"},
{"utm_medium", "cpc"},
{"utm_campaign", "adwords"},
{"utm_term", "api+tooling"},
{"utm_content", "landing"}
};
// metadata can be any custom dictionary
Dictionary<string, object> metadata = new Dictionary<string, object>
{
{"email", "john@acmeinc.com"},
{"first_name", "John"},
{"last_name", "Doe"},
{"title", "Software Engineer"},
{"sales_info", new Dictionary<string, object> {
{"stage", "Customer"},
{"lifetime_value", 24000},
{"account_owner", "mary@contoso.com"}
}
}
};
// Only user_id is required
Dictionary<string, object> user = new Dictionary<string, object>
{
{"user_id", "12345"},
{"company_id", "67890"}, // If set, associate user with a company object
{"campaign", campaign},
{"metadata", metadata},
};
// .NET Core
MoesifMiddleware moesifMiddleware = new MoesifMiddleware(Dictionary<string, object> moesifOptions)
// .NET Framework
// MoesifMiddleware moesifMiddleware = new MoesifMiddleware(OwinMiddleware next, Dictionary<string, object> moesifOptions)
// Update the user asynchronously
moesifMiddleware.UpdateUser(user);
Update Users in Batch
Similar to UpdateUser, but used to update a list of users in one batch.
Only the user_id
field is required.
This method is a convenient helper that calls the Moesif API lib.
For details, visit the C# API Reference.
List<Dictionary<string, object>> usersBatch = new List<Dictionary<string, object>>();
Dictionary<string, object> metadataA = new Dictionary<string, object>
{
{"email", "john@acmeinc.com"},
{"first_name", "John"},
{"last_name", "Doe"},
{"title", "Software Engineer"},
{"sales_info", new Dictionary<string, object> {
{"stage", "Customer"},
{"lifetime_value", 24000},
{"account_owner", "mary@contoso.com"}
}
}
};
// Only user_id is required
Dictionary<string, object> userA = new Dictionary<string, object>
{
{"user_id", "12345"},
{"company_id", "67890"}, // If set, associate user with a company object
{"metadata", metadataA},
};
Dictionary<string, object> metadataB = new Dictionary<string, object>
{
{"email", "mary@acmeinc.com"},
{"first_name", "Mary"},
{"last_name", "Jane"},
{"title", "Software Engineer"},
{"sales_info", new Dictionary<string, object> {
{"stage", "Customer"},
{"lifetime_value", 24000},
{"account_owner", "mary@contoso.com"}
}
}
};
// Only user_id is required
Dictionary<string, object> userB = new Dictionary<string, object>
{
{"user_id", "54321"},
{"company_id", "67890"}, // If set, associate user with a company object
{"metadata", metadataB},
};
usersBatch.Add(userA);
usersBatch.Add(userB);
// .NET Core
MoesifMiddleware moesifMiddleware = new MoesifMiddleware(Dictionary<string, object> moesifOptions)
// .NET Framework
// MoesifMiddleware moesifMiddleware = new MoesifMiddleware(OwinMiddleware next, Dictionary<string, object> moesifOptions)
moesifMiddleware.UpdateUsersBatch(usersBatch);
Update a Single Company
Create or update a company profile in Moesif.
The metadata field can be any company demographic or other info you want to store.
Only the company_id
field is required.
This method is a convenient helper that calls the Moesif API lib.
For details, visit the C# API Reference.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#update-a-company for campaign schema
Dictionary<string, object> campaign = new Dictionary<string, object>
{
{"utm_source", "google"},
{"utm_medium", "cpc"},
{"utm_campaign", "adwords"},
{"utm_term", "api+tooling"},
{"utm_content", "landing"}
};
// metadata can be any custom dictionary
Dictionary<string, object> metadata = new Dictionary<string, object>
{
{"org_name", "Acme, Inc"},
{"plan_name", "Free"},
{"deal_stage", "Lead"},
{"mrr", 24000},
{"demographics", new Dictionary<string, object> {
{"alexa_ranking", 500000},
{"employee_count", 47}
}
}
};
Dictionary<string, object> company = new Dictionary<string, object>
{
{"company_id", "67890"}, // The only required field is your company id
{"company_domain", "acmeinc.com"}, // If domain is set, Moesif will enrich your profiles with publicly available info
{"campaign", campaign},
{"metadata", metadata},
};
// .NET Core
MoesifMiddleware moesifMiddleware = new MoesifMiddleware(Dictionary<string, object> moesifOptions)
// .NET Framework
// MoesifMiddleware moesifMiddleware = new MoesifMiddleware(OwinMiddleware next, Dictionary<string, object> moesifOptions)
// Update the company asynchronously
moesifMiddleware.UpdateCompany(company);
Update Companies in Batch
Similar to updateCompany, but used to update a list of companies in one batch.
Only the company_id
field is required.
This method is a convenient helper that calls the Moesif API lib.
For details, visit the C# API Reference.
List<Dictionary<string, object>> companiesBatch = new List<Dictionary<string, object>>();
// metadata can be any custom dictionary
Dictionary<string, object> metadataA = new Dictionary<string, object>
{
{"org_name", "Acme, Inc"},
{"plan_name", "Free"},
{"deal_stage", "Lead"},
{"mrr", 24000},
{"demographics", new Dictionary<string, object> {
{"alexa_ranking", 500000},
{"employee_count", 47}
}
}
};
Dictionary<string, object> companyA = new Dictionary<string, object>
{
{"company_id", "67890"}, // The only required field is your company id
{"company_domain", "acmeinc.com"}, // If domain is set, Moesif will enrich your profiles with publicly available info
{"metadata", metadataA},
};
// metadata can be any custom dictionary
Dictionary<string, object> metadataB = new Dictionary<string, object>
{
{"org_name", "Contoso, Inc"},
{"plan_name", "Starter"},
{"deal_stage", "Lead"},
{"mrr", 48000},
{"demographics", new Dictionary<string, object> {
{"alexa_ranking", 500000},
{"employee_count", 59}
}
}
};
Dictionary<string, object> companyB = new Dictionary<string, object>
{
{"company_id", "09876"}, // The only required field is your company id
{"company_domain", "contoso.com"}, // If domain is set, Moesif will enrich your profiles with publicly available info
{"metadata", metadataB},
};
companiesBatch.Add(companyA);
companiesBatch.Add(companyB);
// .NET Core
MoesifMiddleware moesifMiddleware = new MoesifMiddleware(Dictionary<string, object> moesifOptions)
// .NET Framework
// MoesifMiddleware moesifMiddleware = new MoesifMiddleware(OwinMiddleware next, Dictionary<string, object> moesifOptions)
moesifMiddleware.UpdateCompaniesBatch(companiesBatch);
Troubleshooting
Issue reading request body in WCF
Certain serializers for Windows Communication Foundation (WCF) may not correctly bind the request body when using logging middleware like Moesif.
If your app uses Windows Communication Foundation (WCF), you may find that your business logic has errors accessing the request body such as for POST
and PUT
requests.
To fix, set the option DisableStreamOverride to true like so:
Dictionary<string, object> moesifOptions = new Dictionary<string, object>
{
{"ApplicationId", "Your Moesif Application Id"},
{"DisableStreamOverride", true},
};
Traditional monolith website broken
Some monolith apps which contain both a website and an API in the same app may issues when API logging middleware is enabled. This is usually due to interactions with other custom middleware.
Since usually this custom middleware is enabled for the website only, the recommended fix is to enable Moesif only for your API.
To do, use the MapWhen
as shown below which only activates the middleware if the Path contains /api
app.MapWhen(context => context.Request.Path.ToString().Contains("/api"), appBuilder =>
{
appBuilder.Use<MoesifMiddleware>(new System.Collections.Generic.Dictionary<string, object> {
{"ApplicationId", "Your Moesif Application Id"}
});
});
The response body not logged
For .NET Core and .NET 5, you will need to set the following option to ensure the response body is logged: More info on this workaround.
.ConfigureKestrel((context, options) => {
options.AllowSynchronousIO = true;
});
Ensuring Errors handled by ExceptionHandler are logged
To capture the API calls handled by ExceptionHandler, please ensure that the app.UseMiddleware<MoesifMiddleware>(moesifOptions);
is before the app.UseExceptionHandler()
in the pipeline.
How to test
- Manually clone the git repo
- From terminal/cmd navigate to the root directory of the middleware.
- Invoke 'Install-Package Moesif.Middleware'
- Add your own application id to 'Moesif.Middleware.Test/MoesifMiddlewareTest.cs'. You can find your Application Id from Moesif Dashboard → Top Right Menu → Installation
- The tests are contained in the Moesif.Middleware.Test project. In order to invoke these test cases, you will need NUnit 3.0 Test Adapter Extension for Visual Studio. Once the SDK is complied, the test cases should appear in the Test Explorer window. Here, you can click Run All to execute these test cases.
Tested versions
Moesif has validated Moesif.Middleware
against the following framework.
Framework Version | |
---|---|
.NET | 5.0 |
.NET | 6.0 |
.NET Core | 2.0-3.0 |
.NET Framework MVC | 4.5-4.7 |
.NET Framework Web API | 4.5-4.7 |
.NET Framework Web API SelfHost | 4.5-4.7 |
Other integrations
To view more documentation on integration options, please visit the Integration Options Documentation.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. 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 Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 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. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- Microsoft.Owin (>= 4.2.2)
- Moesif.Api (>= 2.0.8)
- Newtonsoft.Json (>= 13.0.2)
- System.IdentityModel.Tokens.Jwt (>= 6.8.0)
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- Microsoft.AspNetCore.Http (>= 2.1.22)
- Microsoft.AspNetCore.Http.Extensions (>= 2.1.22)
- Moesif.Api (>= 2.0.8)
- Newtonsoft.Json (>= 13.0.2)
- System.IdentityModel.Tokens.Jwt (>= 6.8.0)
- System.ValueTuple (>= 4.5.0)
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 |
---|---|---|
3.0.9 | 34 | 11/12/2024 |
1.5.1 | 81 | 11/8/2024 |
1.5.0 | 67 | 11/8/2024 |
1.4.9 | 251 | 8/30/2024 |
1.4.8 | 827 | 6/6/2024 |
1.4.7 | 243 | 6/4/2024 |
1.4.6 | 106 | 5/29/2024 |
1.4.5 | 139 | 5/23/2024 |
1.4.4 | 107 | 5/21/2024 |
1.4.3 | 2,550 | 11/8/2023 |
1.4.2 | 112 | 11/7/2023 |
1.4.1 | 119 | 11/3/2023 |
1.4.0 | 155 | 10/31/2023 |
1.3.25 | 12,480 | 8/8/2023 |
1.3.24 | 220 | 7/24/2023 |
1.3.23 | 180 | 6/13/2023 |
1.3.22 | 163 | 6/10/2023 |
1.3.21 | 183 | 6/10/2023 |
1.3.20 | 3,735 | 10/6/2022 |
1.3.19 | 403 | 10/5/2022 |
1.3.18 | 409 | 10/5/2022 |
1.3.17 | 486 | 9/13/2022 |
1.3.16 | 452 | 9/7/2022 |
1.3.15 | 448 | 9/1/2022 |
1.3.14 | 418 | 8/30/2022 |
1.3.13 | 2,938 | 4/15/2021 |
1.3.12 | 426 | 4/1/2021 |
1.3.11 | 405 | 3/26/2021 |
1.3.10 | 528 | 3/18/2021 |
1.3.8 | 476 | 3/12/2021 |
1.3.7 | 442 | 2/9/2021 |
1.3.5 | 448 | 2/4/2021 |
1.3.4 | 416 | 2/2/2021 |
1.3.3 | 421 | 1/15/2021 |
1.3.2 | 484 | 1/9/2021 |
1.3.1 | 624 | 6/15/2020 |
1.3.0 | 499 | 6/15/2020 |
1.2.1 | 485 | 6/11/2020 |
1.1.6 | 557 | 6/9/2020 |
1.1.5 | 491 | 6/8/2020 |
1.1.4 | 525 | 6/8/2020 |
1.1.3 | 806 | 1/7/2020 |
1.1.2 | 594 | 12/19/2019 |
1.1.1 | 588 | 12/14/2019 |
1.1.0 | 566 | 11/15/2019 |
1.0.3 | 585 | 10/22/2019 |
1.0.2 | 593 | 8/27/2019 |
1.0.1 | 705 | 8/23/2019 |
0.2.2 | 603 | 6/26/2019 |
0.2.1 | 605 | 6/18/2019 |
0.2.0 | 618 | 5/30/2019 |
0.1.7 | 601 | 3/23/2019 |
0.1.6 | 659 | 3/1/2019 |
0.1.5 | 636 | 2/25/2019 |
0.1.4 | 616 | 2/25/2019 |
0.1.3 | 667 | 2/11/2019 |
0.1.1 | 752 | 11/19/2018 |
0.1.0 | 786 | 11/17/2018 |