发布不安全code Web应用程序 [英] Publish web application with unsafe code

查看:283
本文介绍了发布不安全code Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发布一个Web应用程序(使用VS2012网络)中,我需要运行一个VB脚本。

该脚本目前并没有因为缺少权限的正确运行可能。我目前正在运行它作为一个用户,并提供一些凭证。我必须提供必须在密码为System.Security.SecureString 这需要创建一个char *。

当我在调试运行我的程序一切正常,并符合市场预期。但是,当涉及到的应用程序发布到服务器的时候,它说:

1 GT; C:\\ SVN \\ ... \\ Default.aspx.cs(108,21,108,27):错误CS0227:不安全code只能出现如果与/不安全编译

我已经允许不安全code在项目属性,但我不知道为什么看到VS在调试,而不是属性时发布时。

当我打出版,我看到错误列表中的CS0227错误,但它保持了仅1秒钟,然后消失......好像是第二个是足以使构建失败。

任何想法的问题是什么?

下面是我的code:

 过程PROC =新工艺();
PSI的ProcessStartInfo =新的ProcessStartInfo(C:\\\\ \\\\的Windows \\\\ System32下将Cscript.exe,\\+ SCRIPTPATH​​ +\\+参数);
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;不安全
{
    //实例化一个新的安全字符串。
    固定(字符* PChars中= PWD)
    {
        hashPwd =新为System.Security.SecureString(PChars中,pwd.Length);
    }
}psi.Password = hashPwd;
//设置进程的启动信息
proc.StartInfo =磅;//我们启动脚本。
proc.Start();


解决方案

这很简单,用不安全code发布

下面是你如何做到这一点:

I'm trying to publish a web application (with VS2012 Web) in which I need to run a vb script.

That script currently doesn't run correctly probably because of the lack of permissions. I am currently trying to run it as a user and supply some credentials. The password I have to provide must be in a System.Security.SecureString which needs a char* to be created.

When I run my app in debug everything works fine and as expected. But when comes the time to publish the app to the server, it says :

1>C:\SVN\...\Default.aspx.cs(108,21,108,27): error CS0227: Unsafe code may only appear if compiling with /unsafe

I have allowed for unsafe code in the project properties, but I don't know why VS sees that property when debugging and not when publishing.

When I hit publish, I see the CS0227 error in the error list but it stays for only 1 second, then it disappears... It seems like that second is enough to make the build fail.

Any ideas as to what the problem is?

Here is my code :

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();

解决方案

It's very simple to publish with a unsafe code

Here is how you do it:

这篇关于发布不安全code Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆