从我的asp.net mvc Web应用程序调用asp.net控制台应用程序 [英] Calling an asp.net console application from my asp.net mvc web application

查看:92
本文介绍了从我的asp.net mvc Web应用程序调用asp.net控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Visual Studio 2012创建了一个asp.net控制台应用程序,该控制台应用程序是我们ERP系统和自定义数据库之间的同步作业。现在,我需要此同步作业及时运行,因此我在Windows任务计划程序下创建了一个新任务,该任务每小时调用一次控制台应用程序,效果很好。

I have created an asp.net console application using visual studio 2012, the console application is a sync job between our ERP system and our custom Database. now i need this sync job to run on timely basis , so i created a new task under our windows task scheduler , which calls the console application each hour, which works well.

但我需要有能力由最终用户手动运行控制台应用程序,主要是用户可以登录到我们的Web应用程序(asp.net mvc),然后从那里可以单击同步按钮,其中同步按钮将主要调用控制台应用程序...这可能吗?我的意思是我可以让我的Web应用程序调用控制台应用程序,就像Task Schuler调用控制台应用程序一样吗?​​

but i need to have the ability to run the console application manually by end users,, mainly users can login to our web application (asp.net mvc) and from there they can click on "Sync" button , where this "Sync" button will mainly calls the console application... so is this possible ? i mean can i have my web application calls the console application , the same way the Task Schuler calls the console application ?

第二个问题,如果我设法调用控制台应用程序从我的asp.net mvc Web应用程序中,这将迫使控制台应用程序在IIS下运行吗?还是Web应用程序可以在IIS范围之外调用控制台应用程序?类似于从任务计划程序调用控制台应用程序?

second question, if I manage to call the console application from my asp.net mvc web application,, will this force the console application to run under IIS ? or the web application can call the console application outside the IIS scope ? similar to calling the console application from Task scheduler ?

推荐答案

问题1:是的。

public ActionResult Index()
{
    Process.Start(@"c:\Windows\System32\cmd.exe");
    return View();
}

问题2:该进程将在IIS帐户下运行,该帐户可能没有特权您的过程需要。您可以在调用Process.Start()之前模拟其他用户。参见以下示例:

Question2: The process will run under the IIS account, which may not have the privileges your process needs. You can impersonate another user before calling Process.Start(). See this example:

更改运行Windows窗体程序的用户

这篇关于从我的asp.net mvc Web应用程序调用asp.net控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆