CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
SanitizingExceptionInspector.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="SanitizingExceptionInspector.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Server-side sanitizing exception inspector.</summary>
7//-----------------------------------------------------------------------
8using System;
9using Microsoft.Extensions.Hosting;
10using Microsoft.Extensions.Logging;
11
12namespace Csla.Server
13{
20 {
21
22 private readonly IHostEnvironment _hostEnvironment;
23 private readonly ApplicationContext _applicationContext;
24 private readonly ILogger _logger;
25
32 public SanitizingExceptionInspector(IHostEnvironment environment, ApplicationContext applicationContext, ILogger<SanitizingExceptionInspector> logger)
33 {
34 _hostEnvironment = environment;
35 _applicationContext = applicationContext;
36 _logger = logger;
37 }
38
48 public void InspectException(Type objectType, object businessObject, object criteria, string methodName, Exception ex)
49 {
50 // Shortcut if we are not running on the server-side of a remote data portal operation
51 if (_applicationContext.ExecutionLocation != ApplicationContext.ExecutionLocations.Server ||
52 _applicationContext.LogicalExecutionLocation != ApplicationContext.LogicalExecutionLocations.Server)
53 return;
54
55 // Shortcut if we are running in development (max. developer productivity)
56 if (_hostEnvironment.IsDevelopment())
57 return;
58
59 // Sanitize in all remaining scenarios
60 string identifier = Guid.NewGuid().ToString();
61 string message = Properties.Resources.ServerSideDataPortalException + Environment.NewLine + ex.ToString();
62 _logger.LogError(message, identifier);
63 throw new ServerException(identifier);
64 }
65 }
66}
Provides consistent context information between the client and server DataPortal objects.
ExecutionLocations
Enum representing the locations code can execute.
LogicalExecutionLocations
Enum representing the logical execution location The setting is set to server when server is execting...
Sanitizing implementation of exception inspector, for hiding sensitive information in exception detai...
void InspectException(Type objectType, object businessObject, object criteria, string methodName, Exception ex)
Logs the exception that occurred during DataPortal call, then throws a generic, less detailed excepti...
SanitizingExceptionInspector(IHostEnvironment environment, ApplicationContext applicationContext, ILogger< SanitizingExceptionInspector > logger)
Constructor.
Sanitized server-side data portal exception; used to avoid the transmission of sensitive server-side ...
Implement this interface to check a DataPortalException before returning Exception to the client.