我正在尝试发布一个需要在其中运行 vb 脚本的 Web 应用程序(使用 VS2012 Web)。
该脚本当前无法正确运行,可能是因为缺少权限。我目前正在尝试以用户身份运行它并提供一些凭据。我必须提供的密码必须在一个System.Security.SecureString
需要创建 char* 的地方。
当我在调试中运行我的应用程序时,一切正常且符合预期。但是到了将应用程序发布到服务器的时候,它会说:
1>C:\SVN\...\Default.aspx.cs(108,21,108,27): error CS0227: Unsafe code may only appear if compiling with /unsafe
我已经在项目属性中允许了不安全的代码,但我不知道为什么 VS 在调试时看到该属性而不是在发布时看到该属性。
当我点击发布时,我在错误列表中看到了 CS0227 错误,但它只停留了 1 秒钟,然后消失了……似乎那一秒钟足以使构建失败。
关于问题是什么的任何想法?
这是我的代码:
Process proc = new Process();
ProcessStartInfo psi = new ProcessStartInfo("C:\\Windows\\System32\\cscript.exe", "\"" + scriptPath + "\" " + args);
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
psi.Domain = "MyDomain";
psi.UserName = "MyUsername";
System.Security.SecureString hashPwd;
unsafe
{
// Instantiate a new secure string.
fixed (char* pChars = pwd)
{
hashPwd = new System.Security.SecureString(pChars, pwd.Length);
}
}
psi.Password = hashPwd;
//Set the process' start info
proc.StartInfo = psi;
//We start the script.
proc.Start();