本文介绍了如何处理System.Security.SecurityException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Experts,
我正在尝试在asp.net中运行批处理文件,我的代码在离线模式下正常工作,
但是当我正在制作时,它给我System.Security.SecurityException错误,
并且无法运行代码,即使我已经web.config文件中的更改。
请帮助我。
Hello Experts,
I am trying to run a batch file in asp.net, where my code is properly working on offline mode,
but when i am making live, its giving me "System.Security.SecurityException" error,
and not able to run the code, even i have been changes in web.config file.
kindly help me.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if(Page.IsPostBack)
{
string exec = TextBox1.Text;
// Get the full file path
string strFilePath = Server.MapPath("fine.bat");
// Create the ProcessInfo object
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
// Start the process
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
// Open the batch file for reading
//System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath);
System.IO.StreamReader strm = proc.StandardError;
// Attach the output for reading
System.IO.StreamReader sOut = proc.StandardOutput;
// Attach the in for writing
System.IO.StreamWriter sIn = proc.StandardInput;
sIn.WriteLine(exec);
strm.Close();
// Exit CMD.EXE
string stEchoFmt = "# {0} run successfully. Exiting";
sIn.WriteLine(String.Format(stEchoFmt, strFilePath));
sIn.WriteLine("EXIT");
// Close the process
proc.Close();
// Read the sOut to a string.
string results = sOut.ReadToEnd().Trim();
// Close the io Streams;
sIn.Close();
sOut.Close();
// Write out the results.
string fmtStdOut = "<font face=courier size=0>{0}</font>";
this.Response.Write("<br>");
this.Response.Write("<br>");
this.Response.Write("<br>");
this.Response.Write(String.Format(fmtStdOut, results.Replace(System.Environment.NewLine, "<br>")));
}
}
}
推荐答案
这篇关于如何处理System.Security.SecurityException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!