开发者

Executing C# or VB.NET code at Runtime

Been spending some time on Codility.com recently and it crossed my mind; how do they execute the code you have created (Specificall开发者_开发技巧y pertaining to C# and VB.NET) ?

What I am basically wondering is how would I take a textbox on a form type some code in it and then run that code? Is this possible without 3rd party tools?

Also how would you prevent security violations specifically pertaining to a web based implementation of such a program?


Have a look at http://msdn.microsoft.com/en-us/library/system.codedom.compiler.aspx Executing such code in a web app is in deed a security problem. .Net provides a set of functionalities to help you solve that problem, like the possibility to run your compiled code in a different app domain as a different user.


With the CSharpCodeProvider class you can compile code (as a string) during runtime.


You can compile code in VB.Net and C# at runtime. Have a look at code to do that here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜