简体   繁体   English

ASP.NET C#MVC网站,如何在点击按钮时安装驱动器?

[英]ASP.NET C# MVC Website, how can I mount a drive upon button click?

I am open to ways to solve this problem. 我愿意解决这个问题。 I suspect the best way is to submit to the controller the path to be mounted and the controller will then pass back a python script that runs locally and mounts the path. 我怀疑最好的方法是向控制器提交要安装的路径,然后控制器将传回一个本地运行的python脚本并安装路径。 Later we may need to verify Active Directory permissions but that's another question. 稍后我们可能需要验证Active Directory权限,但这是另一个问题。 We are able to configure all clients and servers as we wish, so somehow we should be able to allow the mount script to run after downloading. 我们可以按照自己的意愿配置所有客户端和服务器,因此我们应该能够允许mount脚本在下载后运行。 Only really concerned with mounting on windows but mac is optional. 只关心安装在Windows上,但mac是可选的。 My main concern is how to get the server to send the script and get client to run the script, and if this is the right approach to satisfying this necessity; 我主要担心的是如何让服务器发送脚本并让客户端运行脚本,如果这是满足这种必要性的正确方法; The second concern is how I form the path to access any arbitrary remote server share and the third concern is checking permissions first. 第二个问题是我如何形成访问任意任意远程服务器共享的路径,第三个问题是首先检查权限。 Any help appreciated. 任何帮助赞赏。

 public ActionResult ProjectMountSubmit(string project_path, int project_number) {
            //Send mount script to user and make him run it
            return RedirectToAction("Project", "Home", new { ProjectNumber = project_number });
        }

Final Answer to submit a script to the browser. 最终答案将脚本提交给浏览器。 User can also set the browser to open it automatically, python must also be installed and associated to .py files to allow quick double click to run. 用户还可以设置浏览器自动打开它,还必须安装python并将其与.py文件关联,以便快速双击运行。 Not sure if that script/python mime is valid but it works. 不确定该脚本/ python mime是否有效但它是否有效。 Improvements could include somehow using razor to modify a python script so that it isn't all inside quotes, losing color coding. 改进可能包括使用razor修改python脚本,以便它不是所有内部引号,失去颜色编码。 Note you have to escape slashes twice recursively, one for the file stream and one for the script that gets downloaded and run. 请注意,您必须递归两次转义斜杠,一个用于文件流,另一个用于下载和运行的脚本。

public ActionResult ProjectMountSubmit(int project_number, string drive_letter) {
            ProjectsBAL b = new ProjectsBAL();
            Projects c = b.GetProject(project_number);
            //generate python mount script
            string script = "import ctypes\n" +
                            "import subprocess\n" +
                            "import os\n" +
                            "command = 'net use " + drive_letter + ": \\\\\\\\MSI\\\\Users\\\\gunslingor\\\\Desktop\\\\Storage\\\\" + c.CompanyName + "\\\\Clients\\\\" + c.ClientName + "\\\\" + c.ProjectNumber + "_" + c.ProjectName + "'\n" +
                            "returned = subprocess.Popen(command, shell = True, stdout = subprocess.PIPE, stderr = subprocess.PIPE)\n" +
                            "cmd_err_lines = returned.stderr.readlines()";

            var stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);
            writer.Write(script);
            writer.Flush();
            stream.Position = 0;
            //Send mount script to user, double click to run (python must be installed and associated to the file type py)
            return File(stream, "script/python", "Automount.py");
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从ASP.NET MVC网站中生成可下载的c#类? - How can I generate a downloadable c# class from within an ASP.NET MVC website? C#ASP.NET MVC创建按钮在单击时不起作用 - C# ASP.NET MVC Create Button is not working on click 如何单击div中的按钮以不刷新整个页面asp.net C# - how can I click on button inside div to not to refresh whole page asp.net C# c# asp.net 当我单击 gridview 中的按钮时,如何更改按钮的图像 url(其类型为图像) - c# asp.net how can i change the image url of button (it's type is image ) when i click the button in gridview 在gridview中单击“编辑”按钮时,如何调用“删除行”事件? asp.net C# - How can I call “delete row ” event when i click on “edit” button in gridview? asp.net C# ASP.net c#按钮点击 - ASP.net c# button click 如何验证 asp.net C# 中的按钮单击表达式 - How to validate expression on button click in asp.net C# 通过单击表单上的ac#asp.net按钮,如何在继续执行下一行代码之前执行一行代码? - By the click of a c# asp.net button on a form, how can I execute a line of code before moving on to the next lines of code? 如果用户单击按钮,则使用c#通过asp.net在数据库中创建数据库表,怎么办? - if the user click on button then the database table is created in database through asp.net with c#,how can do? 如何在 ASP.Net 中单击按钮时显示/隐藏面板 - How to Show/Hide a Panel upon Click of a Button in ASP.Net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM