Skip to content

Commit

Permalink
Merge pull request #480 from MindscapeHQ/cd/ACT-64/update-asp-dot-net…
Browse files Browse the repository at this point in the history
…-web-api-sections-in-readme

[ACT-64] Update ASP.NET Framework MVC and WebAPI READMEs
  • Loading branch information
crystalqdm authored Jun 6, 2023
2 parents 5338787 + ec8dc54 commit 773b933
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 39 deletions.
4 changes: 4 additions & 0 deletions Mindscape.Raygun4Net.Mvc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ The main classes can be found in the Mindscape.Raygun4Net namespace.
Usage
======

The following instructions are for ASP.NET *Framework* Web API. For instructions for how to install Raygun for ASP.NET Core Web API, see the `Mindscape.Raygun4Net.AspNetCore` provider [here](../Mindscape.Raygun4Net.AspNetCore/README.md).

---

Add a section to configSections:

<section name="RaygunSettings" type="Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net"/>
Expand Down
61 changes: 55 additions & 6 deletions Mindscape.Raygun4Net.WebApi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,58 @@ The main classes can be found in the Mindscape.Raygun4Net namespace.
Usage
======

Add a section to configSections:
The following instructions are for ASP.NET *Framework* Web API. For instructions for how to install Raygun for ASP.NET Core Web API, see the `Mindscape.Raygun4Net.AspNetCore` provider [here](../Mindscape.Raygun4Net.AspNetCore/README.md).

---

Install the **Mindscape.Raygun4Net.WebApi** NuGet package into your project. You can either use the below dotnet CLI command, or the NuGet management GUI in the IDE you use.

```bash
dotnet add package Mindscape.Raygun4Net.WebApi
```

In your Web.config file, find or add a `<configSections>` element, which should be nested under the `<configuration>` element, and add the following entry:

```xml
<section name="RaygunSettings" type="Mindscape.Raygun4Net.RaygunSettings, Mindscape.Raygun4Net"/>
```

Add the Raygun settings configuration block from above:
Then reference it by adding the following line somewhere after the `configSections` tag. Your app API key is displayed when you create a new application in your Raygun account, or can be viewed in the application settings. `RaygunSettings` has many options which can be found [here](https://raygun.com/documentation/language-guides/dotnet/crash-reporting/webapi/#exclude-errors-by-http-status-code).

```xml
<RaygunSettings apikey="paste_your_api_key_here" />
```
<RaygunSettings apikey="YOUR_APP_API_KEY" />
```


Now you can either setup Raygun to send unhandled exceptions automatically or/and send exceptions manually.

To send unhandled exceptions automatically, go to the WebApiConfig class in your project. In the static Register method, call the static RaygunWebApiClient.Attach method.
---

To send unhandled exceptions automatically, go to your `WebApiConfig` class (typically in the `App_Start` directory). Call the static `RaygunWebApiClient.Attach(config)` method from within the `Register` method:

```csharp
RaygunWebApiClient.Attach(config);
using Mindscape.Raygun4Net.WebApi;
```

```csharp
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
RaygunWebApiClient.Attach(config);

// Web API routes here
}
}
```

If you haven't already, make sure to register the `WebApiConfig` class in the `Application_Start` method in your `Global.asax.cs` file:

```csharp
protected void Application_Start()
{
GlobalConfiguration.Configure(WebApiConfig.Register);
}
```

Anywhere in you code, you can also send exception reports manually simply by creating a new instance of the RaygunWebApiClient and call one of the Send or SendInBackground methods.
Expand All @@ -47,6 +81,21 @@ catch (Exception e)
}
```

---

TLS Configuration
-------------------

Raygun's ingestion nodes [require TLS 1.1 or TLS 1.2](https://raygun.com/documentation/privacy-security/transport-layer-security/). If you are using .NET 4.5 or earlier, you may need to enable these protocols in your application. This is done by updating the protocol property in the `Application_Start` method in your `Global.asax.cs` file:

```csharp
protected void Application_Start()
{
// Enable TLS 1.1 and TLS 1.2 with future support for TLS 3
ServicePointManager.SecurityProtocol |= (SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls3 );
}
```

Providing a custom RaygunClient to the automatic exception handlers
===================================================================

Expand Down
43 changes: 10 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Projects built with the following frameworks are supported:
* .NET 3.5 and 4.0 Client Profile
* .NET Core 1.0, 2.0, 3.0+
* ASP.NET
* Mvc
* WebApi
* ASP.NET MVC
* ASP.NET WebApi
* WinForms, WPF, console apps etc
* Windows 8
* WinRT
Expand Down Expand Up @@ -223,44 +223,21 @@ To do this, get your Http Application to implement the IRaygunApplication interf
The http module will use the RaygunClient returned from this method to send the unhandled exceptions.
In this method you can setup any additional options on the RaygunClient instance that you need - more information about each feature is described at the end of this file.

### MVC
### ASP.NET MVC

As of version 4.0.0, Mvc support has been moved into a new NuGet package.
If you have an Mvc project, please uninstall the Raygun4Net NuGet package and install the Mindscape.Raygun4Net.Mvc NuGet package instead.
The NuGet package will include a readme containing everything you need to know about using it.
If you have an Mvc project, please uninstall the Raygun4Net NuGet package and install the `Mindscape.Raygun4Net.Mvc` NuGet package instead.

The Mvc and WebApi NuGet packages can be installed in the same project.
Once the package is installed, see the [package README](/Mindscape.Raygun4Net.Mvc/README.md) for instructions on configuration.

### Web Api

As of version 4.0.0, WebApi support has been moved into a new NuGet package.
If you have a WebApi project, please uninstall the Raygun4Net NuGet package and install the Mindscape.Raygun4Net.WebApi NuGet package instead.

Once the package is installed, go to the `WebApiConfig` class in your project.
In the static `Register` method, call the static `RaygunWebApiClient.Attach` method.

```csharp
RaygunWebApiClient.Attach(config);
```
The Mvc and WebApi NuGet packages can be installed in the same project safely.

Note that you may experience errors if you include the HTTP Module in the `<system.web>` section of your `web.config`.
The HTTP module is only required if you are using MVC or regular ASP.NET - all WebApi errors are caught using
`RaygunWebApiClient.Attach`.
### ASP.NET Web API

To include the HTTP request details, pass in the current request message to the client's SetCurrentHTTPRequest method when manually sending exceptions.
As of version 4.0.0, WebApi support has been moved into a new NuGet package.
If you have a WebApi project, please uninstall the Raygun4Net NuGet package and install the `Mindscape.Raygun4Net.WebApi` NuGet package instead.

```csharp
try
{
// Do something here that might go wrong
}
catch (Exception e)
{
var client = new RaygunWebApiClient();
client.SetCurrentHttpRequest(ActionContext.Request);
client.SendInBackground(e);
}
```
Once the package is installed, see the [package README](/Mindscape.Raygun4Net.WebApi/README.md) for instructions on configuration.

The Mvc and WebApi NuGet packages can be installed in the same project safely.

Expand Down

0 comments on commit 773b933

Please sign in to comment.