La Stampa in rete da ASP.Net/C# può essere fatto utilizzando:
se la rete è configurato per gli utenti e stampante dominio viene aggiunto al server di stampa:
- printerName per essere definito come = "\\ \\ PrintServerIP_OR_Name nomeStampante" Esempio: PrinterSettings.PrinterName = "\\ 15.1.1.1 \\ prn001"
- Controllare il set di autorizzazioni sulla stampante ad accesso
- che o essere Users o Everyone Domain
- Se gli utenti di dominio, quindi il codice C# possono essere racchiuse all'interno della rappresentazione che può essere utilizzato per chiamare il codice di stampa che è il seguente:
/// <summary>
/// Does the actual impersonation.
/// </summary>
/// <param name="userName">The name of the user to act as.</param>
/// <param name="domainName">The domain name of the user to act as.</param>
/// <param name="password">The password of the user to act as.</param>
private void ImpersonateValidUser(
string userName,
string domain,
string password)
{
WindowsIdentity tempWindowsIdentity = null;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
try
{
if (RevertToSelf())
{
if (LogonUser(
userName,
domain,
password,
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
ref token) != 0)
{
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
finally
{
if (token!= IntPtr.Zero)
{
CloseHandle(token);
}
if (tokenDuplicate!=IntPtr.Zero)
{
CloseHandle(tokenDuplicate);
}
}
}
/// <summary>
/// Reverts the impersonation.
/// </summary>
private void UndoImpersonation()
{
if (impersonationContext!=null)
{
impersonationContext.Undo();
}
}
private WindowsImpersonationContext impersonationContext = null;
Prima effettuare una chiamata per rappresentare l'utente e quindi chiamare la funzione di stampa che sarebbe simile di seguito:
if(ImpersonateValidUser("username", "domain", "password"))
{
PrintDetails();
UndoImpersonation();
}
fonte
2016-05-14 12:21:39
In quale contesto utente è in esecuzione ASP.NET? Stai usando l'imitazione? Quali sono i permessi sulla stampante? – Heinzi
È in esecuzione in ASP.NET Development Server, quindi presumo sia in esecuzione con il mio account Windows. Sono in grado di stampare direttamente da Blocco note a quella stampante server. – Prabhu