Trying titanium web proxy with .NET 4.8 build RRS feed

  • Question

  • Hello crowd,

    We understand that using net framework is significantly slower than net core (https://github.com/justcoding121/Titanium-Web-Proxy/issues/773), but is it necessary to reinstall visual studio with only net core and then deselect framework?

    We have made a windows service, that works, but the testing of this titanium web proxy fails. Maybe it has to do with certificate?

    Here is our code, we tested:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading.Tasks;
    using Titanium.Web.Proxy;
    using Titanium.Web.Proxy.EventArguments;
    namespace WebProxy1 {
        public partial class MyNewService : ServiceBase {
            public ProxyServer proxyServer;
            public MyNewService() {
            protected override void OnStart(string[] args) {
                proxyServer = new ProxyServer(true, true, true);
                proxyServer.BeforeRequest += OnRequest;
                WriteToFile("Service is started at " + DateTime.Now);
            protected override void OnStop() {
                WriteToFile("Service is stopped at " + DateTime.Now);
            public void WriteToFile(string Message) {
                string path = "E:\\Downloads\\Logs";
                if (!Directory.Exists(path)) {
                string filepath = "E:\\Downloads\\Logs\\ServiceLog_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".txt";
                if (!File.Exists(filepath)) {
                    // Create a file to write to.   
                    using (StreamWriter sw = File.CreateText(filepath)) {
                } else {
                    using (StreamWriter sw = File.AppendText(filepath)) {
            public async Task OnRequest(object sender, SessionEventArgs e) {
                // To cancel a request with a custom HTML content
                // Filter URL
                if (e.HttpClient.Request.Method.ToUpper() == "GET" && e.HttpClient.Request.RequestUri.AbsoluteUri.Contains("google.com")) {
                    e.Ok("<!DOCTYPE html>" +
                        "<html><body><h1>" +
                        "Website Blocked" +
                        "</h1>" +
                        "<p>Blocked by titanium web proxy.</p>" +
                        "</body>" +
                // Redirect example
                if (e.HttpClient.Request.RequestUri.AbsoluteUri.Contains("wikipedia.org")) {

    When program is running as a windows service, it correctly logs start time to a file. And thereafter nothing else, when we browse some web pages, where it should have logged those internet requests too.

    Monday, October 5, 2020 12:50 PM


  • " but is it necessary to reinstall visual studio with only net core and then deselect framework?"

    Not sure what you mean here. The .NET Framework is installed as part of the OS and other features. You cannot remove it. But if you aren't targeting it then it doesn't matter. There is nothing to uninstall.

    " And thereafter nothing else, when we browse some web pages,"

    I'm not sure we're going to be much help here. The use of third party products is not supported in these forums. You're going to need to ask for help in the forums of whoever is providing the library you're using. It's possible you're missing some steps or there are restrictions on what it can see. 

    The fact that you're doing this in a service is the only thing that becomes actionable. If the code works outside a service but not inside then the issue is with the proxy and service. Otherwise it is most likely just your code. For service related issues the problems are generally either security or dependencies. In the case of security the service normally needs to run as a network service to access network resources. I'm not sure where the proxy resides in this regard but I'd assume it is on the network side. If you're running as SYSTEM then that wouldn't have sufficient network access.

    On the dependencies side you'd need to depend on the network before you could access the proxy (or the proxy service itself most likely). So you need to ensure your service setup creates the dependency otherwise the service may start before its dependents. This is most commonly seen when the service does not work properly at startup but works if you manually start it.

    If it is neither of those then you're going to have to go back to the library provider and see if they can help you.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Kalmydius Monday, October 5, 2020 5:55 PM
    Monday, October 5, 2020 1:42 PM