从asp.net调用服务器上的exe
想要在我的服务器上运行asp.net的exe文件,这可能吗?从asp.net调用服务器上的exe
我用这个方法:
System.Diagnostics.Process process1 = new System.Diagnostics.Process();
// Set the directory where the file resides
process1.StartInfo.WorkingDirectory = @"D:\dev\Analyzer\bin\Release";
// Set the filename name of the file you want to open
process1.StartInfo.FileName = @"D:\dev\Analyzer\bin\Release\Analyzer.exe";
process1.StartInfo.Arguments = "123";
// Start the process
process1.Start();
它工作时,我调试它,而是把在本地主机上我的网站时,有时我会例外:
用户登录失败“IIS APPPOOL \ DQ '
其中dq是我的网站的名称。
堆栈:
System.Data.SqlClient.SqlException(0x80131904):用户登录失败 'IIS APPPOOL \ DQ'。 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader的dataStream,BulkCopySimpleResultSet System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout,TimeoutTimer timeout,SqlConnection owningObject)上的System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)处的BulkCopyHandler,TdsParserStateObject stateObj) SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,Boolean redirectedUserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions,TimeoutTimer超时)在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,TimeoutTimer超时,SqlConnectionString connectionOp System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions)上System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions,对象providerInfo,字符串newPassword,SqlConnection拥有对象,布尔redirectedUserInstance)的字符串newPassword,布尔redirectedUserInstance) (System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject))上System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool池,DbConnectionOptions选项)上的选项,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection owningConnection)。 System.Data.ProviderBas上的System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)上的System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)处的ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) System.Data.SqlClient.SqlConnection.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)在System.Data.SqlClient.SqlConnection.Open()System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser用户)在System.Data.Linq.SqlClient.SqlProvider System.Data.Linq上System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询)上System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()上的.get_IsSqlCe() D:\ dev \ Analyzer \ Program.cs中的Analyzer.Program.Main(String [] args)中的.DataQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator():第59行
我假设在这里你得到的例外是访问违规。
如果是这种情况,则需要确保为具有足够权限运行可执行文件(并访问它所在的目录)的帐户启动进程UserName
和Password
,或者使用以下命令设置应用程序池这样的账户。
更新:在一个坏的LINQ查询,而不是Process.Start
堆栈跟踪点。什么是例外?我无法从跟踪中得知。
这是怎么回事?
更新2:
检查您的连接字符串和SQL服务器 - 该网站账户无法登录到SQL Server。这与Process.Start
或LINQ语法完全没有关系。
您是否设置了正确的密码?如果您正在使用集成安全性(SSPI=true
),是否确保SQL Server启用了此登录?
这种方法是不推荐的。在服务器上,您的ASP.NET网站也作为一个进程运行。 启动另一个进程将需要一些额外的权限。工作进程尝试使用其自己的用户(IIS APPPOOL \ dq)帐户启动analyzer.exe,并且在那里失败。您将需要运行您的工作进程与另一个帐户有足够的权限启动另一个可执行文件。
顺便说一句,这将打开你的表面区域的威胁。根本不推荐。
谢谢 Gaurav
请提供完整的例外详情。说出一个例外是没有细节的。 – Oded 2011-05-30 18:54:43
该网站使用了什么useraccount,并有权访问这些文件? – Gluip 2011-05-30 18:57:37
此外它需要某些.net权限,这可能不会在大多数主机上授予。 – 2011-05-30 18:59:47