0

Im working on an ASP.NET MVC project that compiles input code to .exe file. Then, my code run this .exe. After success, I just delete that .exe file.

To relaese input code I'm using CSharpCodeProvider class. To run it, I'm using Process class.

Making and deleting exe files seems a little bit tricky to me, because I can't save that files into project directory directly while I'm debugging my program. I need to give special permissions to IIS_USERS. But what to do, when I want to release my project into production? How to deal with filepath? Where to save it?

Now, it looks like this:

string exeName = Path.Combine("C:\\Users\\User\\source\\repos\\proj\\solution\\obj\\Debug", "test.exe");
marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
michasaucer
  • 2,630
  • 4
  • 21
  • 50

2 Answers2

3

To deal with paths you should be using Server.MapPath("~") - This returns the physical Path to the root of the web application.

For example if you have a folder called "MyOutput" in the solution (in parallel to the Controller, Views etc. folders) then you can write Server.MapPath("~/MyOutput/"). This will resolve to a physical path like C:\Users\User\source\repos\proj\solution\MyOutput\

This way you do not have to bother about changing paths in local machines or web servers. Also you should not be putting stuffs in the Obj or Bin folders which are not directly related to the web application.

More samples are available here: Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

Rahatur
  • 2,444
  • 3
  • 29
  • 39
1

How about asking user where to save it?

You could have a form that ask for this path, username, password etc. Or even in a config <appSettings></appSettings>

Then you can use Impersonate to save it, execute it without any permission issue. You could use this to save it locally or to any network drive

Hasta Tamang
  • 2,033
  • 1
  • 14
  • 17