I know that Azure Websites are made to be easy, not have role configs and such...but I was still wondering, is there ANY way to create a Startup Task when using a Website? I'm asking because I would like to ease the deployment of an existing website through FTP and Webmatrix (not recompiling the source and without using Visual Studio), and then use Startup Task to deploy and install additionnal components (Crystal Reports, ActiveX Dll...) Thanks for answers Mokh PS : my question is an copy and paste of this one : Windows Azure Website with a Startup task
Windows Azure Website with a Startup task using Webmatrix 3 or similar (without using Visual Studio)
-
The linked question was specifically about whether it's possible to "deploy an additional IIS provider to GAC", which you can't because of security restrictions. I'll provide an answer to the more general question of "is there ANY way to create a Startup Task when using a Website". – Fernando Correia Jul 25 '13 at 16:35
1 Answers
Yes, there is more than one way to implement functionality equivalent to Cloud Services startup tasks in Windows Azure Websites. The main difference and limitation is that you won't be able to run these startup tasks with elevated privileges.
These approaches take advantage of the fact that the web applications running in Windows Azure Websites can spawn processes and write to disk. They can even cause executable files to run.
So you can, for instance, write an ASP.NET application and use the Application_Start
method in Global.asax
to run a batch file that will install something on the file system. As demonstrated in the WebsiteStartupTask sample project, you could write a Global.asax file like this to execute any command:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
string WindowsDir = Environment.GetEnvironmentVariable("windir");
string command = System.IO.Path.Combine(WindowsDir, @"System32\cmd.exe");
string outputFilePath = Server.MapPath("~/Log.txt");
string arguments = String.Format("/c echo Startup task executed at {0} >>\"{1}\"", System.DateTime.UtcNow.ToString("o"), outputFilePath);
System.Diagnostics.Process.Start(command, arguments);
}
</script>
You could also write a web service or HTTP endpoint that, upon receiving a POST HTTP request, would do the same, so you could trigger your startup task remotely (possibly even submitting parameters to it).
In any case, what you can do at application startup will be limited by the security privileges of the user your application is running as. You won't be able to execute anything that requires administrator privileges, but you'll be able to execute anything that can be executed as a regular user.

- 21,803
- 13
- 83
- 116
-
Do you think Mr Correia, that it will be possible this way (Application_Start in Global.asax) to make possible tasks like install and register third parties ActiveX Dlls ? If the response is yes ,then any idea on how to proceed? Thank you once again !... – user2619587 Jul 25 '13 at 17:25
-
You won't be able to execute anything that requires administrator privileges. I've clarified the answer and provided an example. – Fernando Correia Jul 25 '13 at 18:03
-
Do you think that it is possible to do something like [this] (http://sivarselva.wordpress.com/2012/10/05/how-to-run-crystal-reports-on-azure/) without using visual studio and talking about web roles? if yes, how please? – user2619587 Jul 27 '13 at 17:53