2012-05-02 8 views
0

は、私は以下の例を使用するが、私はまだ例外持っている:技術サポート個人的のためのサーバーパスにファイルを書き込むための偽装に関するユーザー権限は何ですか?

System.Security.Permissions.SecurityPermission ここでは、以下に提示された診断情報:システム」タイプの許可を リクエストを。 Security.Permissions.SecurityPermission、mscorlib

管理者は、ユーザーの資格情報を読み書きする完全な権限を有することを特徴とする

IntPtr userToken = IntPtr.Zero; 
bool success = External.LogonUser( 
    "userID", 
    "domain.com", 
    "MyPassword", 
    (int) AdvApi32Utility.LogonType.LOGON32_LOGON_INTERACTIVE, //2 
    (int) AdvApi32Utility.LogonProvider.LOGON32_PROVIDER_DEFAULT, //0 
    out userToken); 

if (!success) 
{ 
    throw new SecurityException("Logon user failed"); 
} 

using (WindowsIdentity.Impersonate(userToken)) 
{ 
    //Create a new GUID, extract the extension and create a new unique filename 
    string strFileGUID = System.Guid.NewGuid().ToString(); 
    string extension = Path.GetExtension(attachment.AttachmentFileName); 
    string tempfilename = strFileGUID + extension; 

    string path = "ServerPath"; 

    //Open a filestream and write the contents of the file at server path 
    FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); 
    fs.Write(fileContent.Content, 0, fileContent.Content.Length); 
    fs.Flush(); 
    fs.Close(); 

} 

私はこの問題に悩まされているので、助けてもらえますか?

+3

まず、 'System.Security.Permissions.SecurityPermission'は例外ではないクラスです。あなたが見ることができるすべての例外情報を追加できますか?内部例外、スタックトレース、および行番号はすべて役立ちます。 –

+0

以下は、技術サポート担当者の診断情報です。 'System.Security.Permissions.SecurityPermission、mscorlib、Version = 2.0.0.0、Culture = neutral、PublicKeyToken = b77a5c561934e089'タイプのアクセス許可のリクエストに失敗しました。 VirusScanningPOC.VirusScan.Button3_Click(Object sender、EventArgs e) –

+0

ありがとうございますが、これは私たちが必要とする情報をあまり提供していません。例外が発生したときにスクリーンショットを投稿できますか? –

答えて

0

コードが完全信頼として実行されないか、PInvokeまたはローカルファイルにアクセスするための正しい.Netアクセス許可が得られません。 Windowsユーザー権限とはまだ関係ありません。リンクされた質問はあなたに.Net CAS - コードアクセスセキュリティ - Why am I getting a System.Security.Permissions.SecurityPermission error in my .NET Application?を開始させるでしょう。

簡単な方法の1つは、アプリケーションをローカルドライブでローカルに実行することです。完全な信頼を得て、CAS例外を受け取らないようにする必要があります。

+0

我々は、彼らが拒否した信頼レベルタグを含めるようにweb.configを変更するように管理者に頼んだとき、私たちは次の投稿で終わりの解決策を得た:http:// www.codeproject.com/Articles/19830/How-to-Access-Network-Files-using-asp-net –

関連する問題