Windows Azure Website with a Startup task using Webmatrix 3 or similar (without using Visual Studio)

让人想犯罪 __ 提交于 2020-02-15 08:58:06

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/17863618/windows-azure-website-with-a-startup-task-using-webmatrix-3-or-similar-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!