Bun*_*Bun 5 c# asp.net unsafe publishing
我正在尝试发布一个Web应用程序(使用VS2012 Web),我需要在其中运行vb脚本.
该脚本目前无法正常运行,可能是因为缺少权限.我目前正在尝试以用户身份运行它并提供一些凭据.我必须提供的密码必须在一个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();
Run Code Online (Sandbox Code Playgroud)
使用不安全的代码发布非常简单
这是你如何做到的:

似乎在发布时会忽略不安全的项目设置,因此您需要手动打开.CSPROJ文件并包括:
<PropertyGroup>
...
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
那为我解决了。
搜索了此问题,但找不到任何内容。检查* .targets文件中的“不安全”,这导致我进入“ AllowUnsafeBlocks”标记。
请将此代码添加到 Web.config 文件中并检查它是否适合您
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/unsafe" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</compilers>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4653 次 |
| 最近记录: |