Created
July 13, 2021 19:28
-
-
Save campersau/c7489d7a653905415f10d9595f52b453 to your computer and use it in GitHub Desktop.
open bi server - Custom HTTP Handler Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>netstandard2.0</TargetFramework> | |
</PropertyGroup> | |
<!-- References to open bi server --> | |
<ItemGroup> | |
<Reference Include="BiExcellence.OpenBi.Server.License.Abstractions"> | |
<HintPath>C:\OPENBI\BiExcellence.OpenBi.Server.License.Abstractions.dll</HintPath> | |
</Reference> | |
<Reference Include="ibssolution.bioxRepository"> | |
<HintPath>C:\OPENBI\ibssolution.bioxRepository.exe</HintPath> | |
</Reference> | |
<Reference Include="Microsoft.AspNetCore.Http.Abstractions"> | |
<HintPath>C:\OPENBI\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath> | |
</Reference> | |
</ItemGroup> | |
<!-- Copy dll to C:\OPENBI\httpserver\plugins after debug build --> | |
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' "> | |
<Exec Command="copy /Y "$(TargetPath)" "C:\OPENBI\httpserver\Plugins\$(TargetFileName)"" /> | |
</Target> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"profiles": { | |
"ConsoleApp2": { | |
"commandName": "CustomHttpHandlerExample", | |
"executablePath": "C:\\OPENBI\\ibssolution.bioxRepository.exe", | |
"workingDirectory": "C:\\OPENBI\\" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BiExcellence.OpenBi.Server.License.Abstractions; | |
using Ibssolution.biox.Repositoryserver; | |
using Microsoft.AspNetCore.Http; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
namespace CustomHttpHandlerExample | |
{ | |
public class CustomHttpHandler : IAsyncHttpHandler | |
{ | |
private readonly ILicense _license; | |
// Get ILicense from DI | |
public CustomHttpHandler(ILicense license) | |
{ | |
_license = license; | |
} | |
public async Task<bool> ProcessRequest(HttpContext context, ICollection<NameValue> parameters) | |
{ | |
// Check the request path | |
if (context.Request.Path.StartsWithSegments("/mycustomhttphandler")) | |
{ | |
context.Response.ContentType = "text/html"; | |
// Check if user is authentificated | |
if (context.User.Identity.IsAuthenticated) | |
{ | |
await context.Response.WriteAsync($"<h1>Username: {context.User.Identity.Name}</h1>"); | |
} | |
await context.Response.WriteAsync($"License Name: {_license.Name}"); | |
// Mark request as handled | |
return true; | |
} | |
// Request not handled | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment