Skip to content

Bpoe/DotnetCGI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.Net CGI

This code illustrates how to implement the Common Gateway Interface standard with C#. I created a simple CgiContext class that will build an HttpRequestMessage from the environment variables passed by the web server. You can then use that to read the input and respond appropriately.

Why? Why not? This was mostly just educational to see how CGI works as an IPC method.

Sample

using Dotnet.Cgi;
using Newtonsoft.Json.Linq;

var app = new CgiApp();

app.Map(HttpMethod.Get, "/cgi/SampleCgiApp.exe/", async (context, parameters) =>
{
    var responseContent = new JObject
    {
        ["env"] = JObject.FromObject(Environment.GetEnvironmentVariables()),
        ["context"] = JObject.FromObject(context),
        ["requestBody"] = context.Request.Content?.ReadAsStringAsync().Result,
    };

    await context.Created(responseContent);
});

await app.Execute();

About

How to implement CGI in .Net

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages