How to run c# in the browser?

Asked

Viewed 721 times

2

Is there any way to integrate HTML and C#?
Or how to Debug to C#?

So, this question I’m asking so that other people, who know program apps in C#, who are venturing into the Web world end up building a site in C# in place of JS, PHP or others.

As I mentioned in the second question, a C#debug, for online editors, more to check if the code is correct and not to any bug, without the need to run (as entirely a program itself).

  • Direct in browser? Javascript type?

  • @jbueno, yes type Javascript

  • Not at first. I won’t tell you it’s impossible, but it must be a lot of work for little result. Why exactly do you need this? Perhaps, if I explain your problem, we can show you a solution (I’m sure this is not the most viable solution)

  • 1

    @jbueno, type was just a curiosity type if to some point integrate HTML and C#, as HTML and JS , Ruby and HTML, because check this could help many beginners in Web Programming who already know how to program in this language. Or in the case of an online editor build only a debug to C#

  • @Daniel the "J" done is to edit the question and specify better what you want

  • @Daniel, I think you’re confusing things a little bit. Ruby runs on the server (in the same way as C#, PHP, Python, among others) and Javascript runs on the client (in the browser). The best is you [Dit] your question and be more specific, give more details about your question. But anyway, I advise you to read about ASP.NET.

  • @jbueno, ok, but as I said it is not a doubt but a Curiosity and while the Extensions just showed as an example.

  • I don’t know if that’s what you want, but you can run C# directly on this page: https://ideone.com/ choose C# from the list below the box where you type the code.

  • @Math, yes this way only directly on my site, but this already leaves a branch : - ]

  • I get it, you wanted to implement your own compiler online, just like https://www.codecademy.com/ has, right?

  • You also have https://dotnetfiddle.net/

  • @Math, yes that’s right

  • @jbueno, ok I’ll see

Show 8 more comments

2 answers

1

I will not tell you that it is impossible because I have seen people making up a Linux kernel (OS) running through javascript "embedded" in the browser.

Linux emulator with Javascript

But one thing is certain, any solution you want to do right in the browser will not be able to escape from doing it using Javascript as an intermediate language running as C# interpreter/compiler/executor which is brilliant but super complex.

Some solutions usually take a chunk of code, climb it to the server, run there and return the result in HTML.

There are many sites today that simulate the result of a C# code that you can use as a teaching platform for ex:

http://csharppad.com/

Hug !

0

It is not possible to execute C# code directly in the client browser, because the codes are executed on the server and only the pure HTML is returned to the client.

The same concept applies to classic ASP pages, PHP, ASP.Net, etc.

What you can do is by calling jQuery a C# statement on the server, this statement will process and make an HTML return

In addition to this approach being more performative, you have a gain with security, because, imagine writing the connection string directly in the client’s browser.

Example of postback code with jQuery:

$.ajax({
    url: "@Url.Action("DeleteMessage", "Home")",
    type: "POST",
    data: { messageid: GetCurrentMessageID(), mailbox: GetCurrentMailbox() },
    dataType: 'json',
    cache: false,
    success: function (data) {
         //Sucesso, faça algo
    },
    error: function (jqXHR, exception) {
         //Erro
    }
});

I think that so you can have a north, this code I use in an application with ASP.Net MVC, the page makes the call of the code postback and returns to the client only what I want (A message, a grid, etc.)

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.