简体   繁体   中英

Directory considerations when executing a process from an ASP.NET app?

I have an ASP.NET Web role that runs an audio effects utility on sound files generated when a particular Controller method is called. I understand completely how to use the Process object to execute a process, set the working directory, wait for exit, and check the exit code.

Here are my specific questions:

  • If I have the EXE file along with its dependencies in a folder in my ASP.NET project, what do I need to do so that they are put in a non-public directory when the Web Role is published to Azure? Or are they copied to the web site as part of the published package? If so, how do I get the EXE files final location? I assume I just can't reference the EXE via an unadorned "//.exe" path. In other words, I need to know what to do with the EXE file and dependencies (if anything) so it run's correctly and also I need to know where I will find it in the published directory structure so I can pass that info to the Process object's StartInfo property.

  • Are there any web.config file changes I need to make or directory permission settings I need to change to make this work?

NOTE: I am aware of the caveats of running a process from an ASP.NET thread due to scalability and time-out issues:

Launching new process from ASP.NET

However, most of the time the utility will not need to be run because most of the sound files returned by the Controller method have already been generated and are being pulled from a BLOB field in a database. Also, I've timed the conversion and it takes about 200 to 500 milliseconds to run at worst using a single core.

one way of doing this is:

  1. put all your EXE and dependent files into a folder (lets say 'MyFolder')
  2. have the folder as part of your project so that the publish system copies it like normal files.
  3. have the following web.config entry. This ensures nobody can access the file from the URL externally.
  4. in your code, you can always use Server.MapPath to get to the EXE path etc. to be used by the process class.
<location path="MyFolder">
     <system.web>
       <authorization>
         <deny users="*"/>
       </authorization>
     </system.web>
</location>

there may be other ways of preventing access to this folder via:

  1. Url Rewriting rules, so that only http_referrers of your site are allowed to access them. ie no direct hotlinking.
  2. http handlers etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM