Converting C# console application to HTML for browsers?

Stefan Walczak 1 Reputation point

Hello, I tried finding my exact solution before asking but I have a console app I designed that is simply text-based and uses if-else statements and loops (or keeps accepting input and responds) until the user types “no” or “no thank you”. Basically a chatbot.

I couldn’t find if there was any way to make this console app viewable on a website with html? Basically the page load would start the program and the viewer could play around with the program and ask questions on my website. If there was a way to format a console window box that I could size to my liking for my website that would be ideal. Thanks in advance if anyone has any valuable advice!

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,164 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. P a u l 7,651 Reputation points

    Have you looked at websockets?

    They're used to create persistent two-way connections between a client & server:

    Here's a full working example of an .NET MVC app with a websocket enabled:

    When the user visits the site they're served up wwwroot/index.html which establishes a websocket connection with websocket server endpoint listening on the /ws URL on the backend.
    The server then awaits messages from the client in a loop & echos the same message back to the client:

    That's where your chatbot can take over.

    0 comments No comments

  2. Bruce ( 35,716 Reputation points

    you can use the <pre></pre> markup to match console output and <input> to input. the big difference is that the web sites are stateless. that is your console app code would work like it exited after every response. the app would need to save the state for the next run.

    typically with a website you store a state key (or entire state if small) in a cookie. the browser will send this cookie on each request. you use the cookie info to restore state.

    the other issues is that website are multi-threaded, so you can not use static variables to save state (unless its indexed by a user key). also a hosted website may be on several servers so state needs to be available from any server (typically a database or network cache)

    a modern option to store state at user level is to use web sockets. this is a persistent connection, so you can tie state to the connection. signal/r Is library for this, and used for chat style apps.

    0 comments No comments