7

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

3 に答える 3

2

このコードを 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>
于 2013-05-15T14:26:29.070 に答える