This is a way to achieve this using C# MVC .NET and the Python compiler. The versions are really case specific, such as the infrastructure you are making use of.
Within a controller of choice in your Web App:
one can use :
using System.Diagnostics;
ProcessStartInfo start = new ProcessStartInfo();
Console.WriteLine("Starting Python Engine...");
start.FileName = @"~\Python\Python39\python.exe";// you will need to have a copy in an accessible folder.
start.Arguments = string.Format("{0}", @"~/PythonScripts/PythonScriptName.py");
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
Console.WriteLine("Starting Process..." + DateTime.Now.ToString());
Results can be retrieved as for instance:
using (Process process = Process.Start(start)) {
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
} } Console.WriteLine("Process Succeeded..." + DateTime.Now.ToString());
The results can then be populated within a model and sent to your page on Load/Post.
You can see examples of how I make use of this to evaluate z-spreads with a web front-end using python in this manner.
enter link description here