Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从网站下载并运行批处理文件,并运行两次_C#_Batch File_Download - Fatal编程技术网

C# 从网站下载并运行批处理文件,并运行两次

C# 从网站下载并运行批处理文件,并运行两次,c#,batch-file,download,C#,Batch File,Download,这是存储在服务器上的批处理文件: @echo off echo Hello World test 1 echo %time% pause 这是下载bat文件的完整代码: public partial class DeploymentSWUpdate : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { btnDSWUpdate.Attributes.Ad

这是存储在服务器上的批处理文件:

@echo off

echo Hello World test 1

echo %time%

pause
这是下载bat文件的完整代码:

public partial class DeploymentSWUpdate : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        btnDSWUpdate.Attributes.Add("onclick", "javascript:alert('Be sure to Click RUN')");
    }

    protected void btnDSWUpdate_Click(object sender, EventArgs e)
    {
        string FilePath = System.Configuration.ConfigurationManager.AppSettings["DeploymentSWSourcePath"].ToString();
        string FileDest = "Temp_" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".bat"; 

        if (System.IO.File.Exists(FilePath))
            {
                Response.Clear();
                Response.ContentType = "Text/plain";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + FileDest);
                Response.AddHeader("Content-Length", new System.IO.FileInfo(FilePath).Length.ToString());
                Response.WriteFile(FilePath);
                Response.End();
            }
            else
            {
                lblMessage.BackColor = System.Drawing.Color.Tomato;
                lblMessage.Text = "Please contact Tech Support.  Software Update File not found: " + FilePath;
                return;
            }

    }
}
当我点击按钮,我得到运行,保存或取消弹出窗口。如果我点击Run,它会被下载并运行两次

它在VisualStudio中运行良好。但是当我将代码推送到服务器时,批处理文件运行了两次

更新:

唯一的另一个控件是标签,尽管此页使用母版页

链接按钮没有改变任何东西。[他的模板字段建议只能在网格视图中使用,不是吗?]

根据请求,双击屏幕截图

页面上还有哪些其他控件?他们是否也导致了回发?我读过这篇文章,它可能会提供一些线索。你能发布一张图片,看看确切的输出吗?