0

I'm looking a way to run codes provided as a string...

Example: I want to store some asp.net c# codes in a database table and I would like to run it on a page.

For example:

string codesFromDBTable = "Response.Write(abc)" //something like that...

Is that possible?

Erçin Dedeoğlu
  • 4,950
  • 4
  • 49
  • 69

2 Answers2

3

Sure, it's possible using CSharpCodeProvider. But I can't stress enough how careful you should be executing arbitrary code from any source...

You might want to consider isolating the code you compile and execute into a separate AppDomain and limit the privileges available to it.

What exactly is your use case?

Dean Ward
  • 4,793
  • 1
  • 29
  • 36
1

Is something like this what you are looking for?

http://www.codeproject.com/Articles/9019/Compiling-and-Executing-Code-at-Runtime

BCartolo
  • 720
  • 4
  • 21