3

特定のドメイン アカウントのみがアクセスできるネットワーク リソースにアクセスする必要があります。LogonUser 呼び出しを使用していますが、Web アプリケーションが asp.net アカウントで実行されており、この呼び出しを行うための適切なアクセス許可がないため、"ユーザーに必要な権限がありません" という例外が発生します。

それを回避する方法はありますか?ASP.Net アカウントの ID またはアクセス許可を変更することはできません。これは、多くのプロジェクトが実行されている運用マシンであるためです。これを達成するためのより良い方法はありますか?

Asp.Net 2.0、フォーム認証を使用します。

敬具。

4

5 に答える 5

7

LogonUser を呼び出すだけでは十分ではありません。そのユーザーになりすます必要があります。ネットワーク リソースにアクセスするためだけに偽装できます。

サンプル コードはMSDNにあります。

于 2008-10-24T13:52:48.500 に答える
1

を追加できます

<identity impersonate="true" userName=""/>

web.config にタグ付けしますが、そのユーザーとしてサイト全体を実行したくない可能性があるため、理想的ではない可能性があります...

ドメイン名とパスワードを使用して、ネットワーク共有をローカル ドライブとしてマップし、マップされたドライブを介してファイルを Web サイトにプルできますか?

NET USE Z: \\SERVER\Share password /USER:DOMAIN\Username /PERSISTENT:YES
于 2008-10-24T13:31:05.627 に答える
0
  • このWebPartを使用して、アクセスが制限されたネットリソースに接続します。ファイルを配置し、リソースとの接続を閉じます(アクセスが許可されたユーザーとして)。新しい共有接続を作成する必要はありません。 sistemsdepartamentは私になります。必要なインポートはたくさんあるかもしれませんが、私は多くのテストを行っており、コードをクリーンアップする時間がありません。お役に立てば幸いです。(私の英語が下手でごめんなさい)。

インポートシステムインポートSystem.ComponentModelインポートSystem.Web.UIインポートSystem.Web.UI.WebControlsインポートSystem.IOインポートSystem.IO.FileインポートSystem.DiagnosticsインポートSystem.Xml.SerializationインポートMicrosoft.SharePointインポートMicrosoft.SharePoint.UtilitiesインポートMicrosoft.SharePoint.WebPartPagesインポートMicrosoft.SharePoint.WebControlsインポートMicrosoft.SharePoint.AdministrationインポートSystem.Security.PrincipalインポートSystem.Security.PermissionsインポートSystem.Runtime.InteropServicesインポートSystem.EnvironmentインポートSystem.Net.SocketsインポートSystem.Web .UI.HtmlControls

Public Class Impersonalizacion Private Const LOGON32_PROVIDER_DEFAULT As Integer = 0 Private Const LOGON32_LOGON_INTERACTIVE As Integer = 2

<DllImport("advapi32.dll", SetLastError:=True)> _
Public Shared Function LogonUser(ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, ByRef phToken As IntPtr) As Boolean
End Function

<DllImport("advapi32.dll", EntryPoint:="DuplicateToken", ExactSpelling:=False, CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function DuplicateToken(ByVal ExistingTokenHandle As IntPtr, ByVal ImpersonationLevel As Integer, ByRef DuplicateTokenHandle As IntPtr) As Integer
End Function

Public Shared Function WinLogOn(ByVal strUsuario As String, ByVal strClave As String, ByVal strDominio As String) As WindowsImpersonationContext
    Dim tokenDuplicate As New IntPtr(0)
    Dim tokenHandle As New IntPtr(0)
    If LogonUser(strUsuario, strDominio, strClave, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, tokenHandle) Then
        If DuplicateToken(tokenHandle, 2, tokenDuplicate) <> 0 Then
            Return (New WindowsIdentity(tokenDuplicate)).Impersonate()
        End If
    End If
    Return Nothing
End Function

WebPart1の終了クラスの説明。")、XmlRoot(Namespace:=" SPSCopiarFichero ")>_パブリッククラスWebPart1はMicrosoft.SharePoint.WebPartPages.WebPartを継承します

Protected WithEvents File1 As HtmlInputFile

Dim vdestino As String = "\\centappd20nd01\uploads_avisos"
Dim vtemporal As String = "c:\pdf"

Protected WithEvents boton1 As Button
Protected WithEvents usuario As TextBox
Protected WithEvents contra As TextBox
Protected WithEvents dominio As TextBox
Protected WithEvents destino As TextBox
Protected WithEvents origen As TextBox
Protected WithEvents temporal As TextBox
Protected WithEvents log As TextBox
'Render this Web Part to the output parameter specified.
Protected Overrides Sub RenderWebPart(ByVal output As System.Web.UI.HtmlTextWriter)
    log.RenderControl(output)
    output.Write("<br><font>Ruta Origen</font><br>")
    File1.RenderControl(output)
    output.Write("<br><font>Ruta Temporal </font><br>")
    temporal.RenderControl(output)
    output.Write("<br><font>Ruta Destino </font><br>")
    destino.RenderControl(output)
    output.Write("<br><font>Usuario </font><br>")
    usuario.RenderControl(output)
    output.Write("<br><font>Contraseña </font><br>")
    contra.RenderControl(output)
    output.Write("<br><font>Dominio </font><br>")
    dominio.RenderControl(output)
    output.Write("<br><br><center>")
    boton1.RenderControl(output)
    output.Write("</center>")
End Sub
Protected Overrides Sub CreateChildControls()

    dominio = New TextBox
    With dominio
        .Text = "admon-cfnavarra"
        .Width = Unit.Pixel("255")
    End With
    Controls.Add(dominio)

    boton1 = New Button
    With boton1
        .Text = "Copiar Fichero"
    End With
    Controls.Add(boton1)

    File1 = New HtmlInputFile
    With File1

    End With
    Controls.Add(File1)

    usuario = New TextBox
    With usuario
        .Text = "SVCWSINCPre_SNS"
        .Width = Unit.Pixel("255")
    End With
    Controls.Add(usuario)

    contra = New TextBox
    With contra
        .Text = "SVCWSINCPre_SNS"
        .Width = Unit.Pixel("255")
    End With
    Controls.Add(contra)

    destino = New TextBox
    With destino
        .Text = vdestino
        .Width = Unit.Pixel("255")
    End With
    Controls.Add(destino)

    log = New TextBox
    With log
        .Width = Unit.Percentage(100)
        .BackColor = System.Drawing.Color.Black
        .ForeColor = System.Drawing.Color.White
    End With
    Controls.Add(log)

    temporal = New TextBox
    With temporal
        .Text = vtemporal
        .Width = Unit.Pixel("255")
    End With
    Controls.Add(temporal)
End Sub
Private Sub boton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles boton1.Click
    If File1.PostedFile.FileName <> "" Then
        Dim _objContext As WindowsImpersonationContext = Nothing
        log.Text = QuienSoy()
        CopyFile(File1.PostedFile.FileName, temporal.Text)
        _objContext = Impersonalizacion.WinLogOn(usuario.Text, contra.Text, dominio.Text)
        CopyFile(temporal.Text & "\" & System.IO.Path.GetFileName(File1.PostedFile.FileName), destino.Text)
        _objContext.Undo()
    Else
        log.Text = "Se debe introducir un fichero"
    End If
End Sub
Friend Shared Function QuienSoy() As String
    Return WindowsIdentity.GetCurrent().Name
End Function
Public Function CopyFile(ByVal StartPath As String, ByVal EndPath As String)
    Try
        Dim fn As String = System.IO.Path.GetFileName(StartPath)
        System.IO.File.Copy(StartPath, EndPath & "\" & fn, False)
        log.Text = "Fichero Copiado Correctamente"
    Catch ex As Exception
        log.Text = ex.Message
    End Try
End Function

エンドクラス

于 2009-08-25T09:44:34.560 に答える
0

私はこれについて 1.1 未満で親密な経験しかしていないので、2.0 日で状況が変わった可能性がありますが... イントラネット シナリオで展開されるアプリがあり、同じことをします。ID の偽装をオンにし、フォーム モード認証をオンにし、匿名アクセスをオフにして実行します。これを制御する最も簡単な方法 (私が見つけた) は、アクセス権を持つユーザーの資格情報を web.config に入れることです。それらは、ID の偽装を有効にしたノードに移動します。超極秘情報ならこんな風にはしないけど!私たちは印刷環境でのみ共有グラフィックスにアクセスしているので、ほとんどのサイトは、web.confit に入れるための制限付きアカウントを喜んでセットアップします。LogonUser には、昇格された特権が必要です。msdn には、コードで特定のユーザーを偽装する方法に関する優れた記事がいくつかあります。私'

于 2008-10-24T13:40:47.403 に答える
0

ネットワーク リソースを保護する ACL を変更できますか? 私が過去に使ったトリックは、Active Directory グループを作成し、コンピュータ オブジェクトをそのグループに入れるというものでした。次に、アクセスする必要があるオブジェクト (ファイル、共有など) のアクセス制御リストでそのグループを使用します。

これにより、Windows サービスをローカル システムとして実行し、保護されたネットワーク リソースにアクセスできるようになりました。また、このトリックは、Network Service として実行される ASP.NET プロセスでも機能するようです。

于 2008-10-24T13:59:20.173 に答える