使用 Webmatrix 3 或类似的启动任务的 Windows Azure 网站(不使用 Visual Studio)

标签 windows azure web task startup

我知道 Azure 网站制作得很简单,没有角色配置等...但我仍然想知道,在使用网站时有没有办法创建启动任务? 我这样问是因为我想通过 FTP 和 Webmatrix 简化现有网站的部署(不重新编译源代码,也不使用 Visual Studio),然后使用 用于部署和安装附加组件(Crystal Reports、ActiveX Dll...)的启动任务 感谢您的解答 莫克 PS:我的问题是这个问题的复制和粘贴:Windows Azure Website with a Startup task

最佳答案

是的,有不止一种方法可以实现与 Windows Azure 网站中的云服务启动任务等效的功能。主要区别和限制是您将无法使用提升的权限运行这些启动任务。

这些方法利用了这样一个事实:在 Windows Azure 网站中运行的 Web 应用程序可以生成进程并写入磁盘。它们甚至可以导致可执行文件运行。

例如,您可以编写一个 ASP.NET 应用程序并使用 Global.asax 中的 Application_Start 方法来运行一个批处理文件,该文件将在文件系统。正如 WebsiteStartupTask 中所示示例项目,您可以编写一个像这样的 Global.asax 文件来执行任何命令:

<%@ 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>

您还可以编写一个 Web 服务或 HTTP 端点,在收到 POST HTTP 请求时执行相同的操作,这样您就可以远程触发启动任务(甚至可能向其提交参数)。

无论如何,您在应用程序启动时可以执行的操作将受到应用程序运行用户的安全权限的限制。您将无法执行任何需要管理员权限的操作,但您将能够执行任何可以作为普通用户执行的操作。

关于使用 Webmatrix 3 或类似的启动任务的 Windows Azure 网站(不使用 Visual Studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17863618/

相关文章:

Windows 版本预处理器和为向后兼容而构建?

F# 方法指针 "not accessible from this code location"

javascript - Node 应用程序架构 : where does express come into node. js

c# - 使用 C# 提供 HTML

java - 如何使用 selenium webdriver 切换到重定向 url

windows - PowerShell,不包含方法 'items'

Windows 内核驱动程序 : Does the "HANDLE UniqueThread" in "CLIENT_ID CreatingThreadId" is the same during the process loading?

c++ - 当内存限制接近时转储缓冲数据

python - Azure 数据 block : How to read part files and save it as one file to blob?

azure - 如何验证 Azure 反向 DNS 是否正常工作?