当前位置:编程学习 > C#/ASP.NET >>

ASP.NET 执行文件,拒绝访问

ASP.NET 执行批处理文件,代码如下:

string encodeFile = Server.MapPath(ConfigurationManager.AppSettings["batfile"]);
ProcessStartInfo fileStartInfo = new ProcessStartInfo(encodeFile);
fileStartInfo.WindowStyle = ProcessWindowStyle.Normal;
Process.Start(fileStartInfo);


在本机测试无任何问题,发布至服务器上出现拒绝访问,错误提示如下:


Server Error in '/' Application.
--------------------------------------------------------------------------------

拒绝访问。 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ComponentModel.Win32Exception: 拒绝访问。

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[Win32Exception (0x80004005): 拒绝访问。]
   System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) +2097
   System.Diagnostics.Process.Start() +140
   System.Diagnostics.Process.Start(ProcessStartInfo startInfo) +50
   MediaFileUpload.Test.Page_Load(Object sender, EventArgs e) +120
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436



肯请指教!
--------------------编程问答-------------------- 又aspnet访问权限么? --------------------编程问答-------------------- 是不是执行权限的问题,

看看 iis用户是否有 bat 文件的访问和执行权限 --------------------编程问答-------------------- 服务器端配置下,看下 --------------------编程问答--------------------
引用 2 楼 cqq 的回复:
是不是执行权限的问题, 

看看 iis用户是否有 bat 文件的访问和执行权限


请问如何添加访问BAT文件权限 --------------------编程问答-------------------- 是不是文件已经运行了? --------------------编程问答-------------------- 可能是路径的问题或者权限的问题。
我遇到过这种,从这两个地方下手。 --------------------编程问答-------------------- 右键bat文件夹属性,共享和安全,在安全里添加用户 --------------------编程问答-------------------- 已在网站目录添加IIS来宾帐户可执行权限,无效果. --------------------编程问答-------------------- 路径问题不太可能,换成完全物理路径仍然拒绝访问 --------------------编程问答-------------------- 补充点:我更换台服务器,同样程序,文件目录无需做任何设置运行成功 --------------------编程问答-------------------- 最好到策略组中查询关于该件类型的三个操作权,将asp.net及IIS内置用户都给予本地权. --------------------编程问答-------------------- 奇怪的是,我在目录测试时让everyone完全控制,同样出现拒绝访问情况 --------------------编程问答-------------------- 如果你的代码在Global.asax的Appcation_Start中使用Server.MapPath会出错的。

试一下用:
System.Web.HostingEnvironment.MapPath()吧。 --------------------编程问答-------------------- Global.asax的Appcation_Start中使用Server.MapPath  不会出错

日志查看到
执行此处才会报错
Process.Start(fileStartInfo);
--------------------编程问答-------------------- jf --------------------编程问答-------------------- 那就是权根问题了,
Appcation_Start中使用Server.MapPath 是不会出错

是我记错了
如果在类似

Static Config()
{

}
中,再在Appcation_Start会执行不了Server.MapPath
你的代码看样子也没有用这样的代码,应该是权限了,查看系统日志吧,应该有记录。
--------------------编程问答-------------------- 事件类型: 警告
事件来源: ASP.NET 2.0.50727.0
事件种类: Web Event 
事件 ID: 1309
日期: 2008-11-19
事件: 17:34:23
用户: N/A
计算机: SVCTAG-88X372X
描述:
Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 2008-11-19 17:34:23 
Event time (UTC): 2008-11-19 9:34:23 
Event ID: 4f86e5deae864dbbbbc9dcd4333da95d 
Event sequence: 4 
Event occurrence: 1 
Event detail code: 0 
 
Application information: 
    Application domain: /LM/W3SVC/435172584/Root-6-128715608634062500 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: D:\web\video1\ 
    Machine name: SVCTAG-88X372X 
 
Process information: 
    Process ID: 5384 
    Process name: w3wp.exe 
    Account name: NT AUTHORITY\NETWORK SERVICE 
 
Exception information: 
    Exception type: Win32Exception 
    Exception message: 拒绝访问。 
 
Request information: 
    Request URL: http://video.tlx.com.cn:8080/test.aspx 
    Request path: /test.aspx 
    User host address: 218.241.174.82 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: NT AUTHORITY\NETWORK SERVICE 
 
Thread information: 
    Thread ID: 6 
    Thread account name: NT AUTHORITY\NETWORK SERVICE 
    Is impersonating: False 
    Stack trace:    at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at MediaFileUpload.Test.Page_Load(Object sender, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
 
系统日志说的好像NT AUTHORITY\NETWORK SERVICE 没有权限 --------------------编程问答-------------------- 权限问题吧,在权限里给Users赋更多权限吧 --------------------编程问答-------------------- 我也觉得权限的可能性比较大

假如权限无问题的话,就停止了服务,再启动试试

--------------------编程问答-------------------- 注意看:
Process information:
    Process ID: 5384
    Process name: w3wp.exe
    Account name: NT AUTHORITY\NETWORK SERVICE 

在w3p.exe是实际运行.NET代码的进程,它运行的账户是NT AUTHORITY\NETWORK SERVICE,是一个很瘦限制的账户,我记得好像是属于Guests组的。

所以你要确定这个账户有足够的权限运行你要运行的文件。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,