Click here to Skip to main content
15,885,757 members

Comments by sanjayv.gade (Top 7 by date)

sanjayv.gade 18-Jul-12 5:39am View    
Even it prompts for login, i entered valid credentials but it fails and give unauthenticated users.
Login prompt window contains following warning message:
Warning: This server is requesting that your username and password be sent in an insecure manner (basic authentication without a secure connection).
It is for Basic authentication but i configured my application with windows authentication.

It was asking windows authentication login screen two days before and it was working fine.
Problem started from yesterday after restoring database.
sanjayv.gade 2-Apr-12 7:33am View    
Actually i want a status of jobs from task scheduler through application. for that i have used dll it has a function which retrives job status. application hosted on windows server 2008-R2, on this server we want some rights so we need to do impersonation.

You are right, Only service or admin account can impersonate other users. and i have service/admin account, when i provide admin details into the web config file it works fine. but it is not working same with coding(VB.Net)

below is code i have tried:

Public Function StartImpersonation(ByVal sUserName As String, ByVal sDomain As String, ByVal sPassword As String) As Boolean

Dim bResults As Boolean = False Dim sErrorMessage As String

Dim oWindowsIdentity As WindowsIdentity

Dim hPrimaryToken As IntPtr = IntPtr.Zero 'a Win32 handle to our authentication token

Dim hImpersonationToken As IntPtr = IntPtr.Zero 'a Win32 handle to our impersonation token

If sUserName = String.Empty Then

Throw New ArgumentException("UserName may not be NULL or String.Empty")

End If 'If no domain is given, assume the account is a local one

If sDomain = String.Empty Then

sDomain = Environment.MachineName End If Try

'Validate the provided userid, password and domain.

If LogonUserA(sUserName, sDomain, sPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hPrimaryToken) <> 0 Then

'Convert our token to one whos handle has TOKEN_IMPERSONATE set

If DuplicateToken(hPrimaryToken, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, hImpersonationToken) <> 0 Then

'Create a new identity object based on our impersonation token

oWindowsIdentity = New WindowsIdentity(hImpersonationToken)

'Switch to our new identity

m_oImpersonationContext = oWindowsIdentity.Impersonate()

If Not (m_oImpersonationContext Is Nothing) Then

m_bImpersonationActive = True

bResults = True End If

Else

sErrorMessage = String.Format("DuplicateToken failed (rc={0})", Runtime.InteropServices.Marshal.GetLastWin32Error)

'Throw New Security.Authentication.AuthenticationException(sErrorMessage)

End If Else

sErrorMessage = String.Format("LogonUser failed (rc={0})", Runtime.InteropServices.Marshal.GetLastWin32Error)

'Throw New Security.Authentication.AuthenticationException(sErrorMessage)

End If Finally

If Not hImpersonationToken.Equals(IntPtr.Zero) Then

CloseHandle(hImpersonationToken)

hImpersonationToken = IntPtr.Zero End If

If Not hPrimaryToken.Equals(IntPtr.Zero) Then

CloseHandle(hPrimaryToken)

hPrimaryToken = IntPtr.Zero End If End Try

Return bResults End Function
sanjayv.gade 2-Apr-12 7:27am View    
Actually i want a status of jobs from task scheduler through application.

for that i have used dll it has a function which retrives job status. application hosted on windows server 2008-R2, on this server we want some rights so we need to do impersonation. but i am not calling any exe file, then Is it right to create new proccess thread for that?
sanjayv.gade 29-Mar-12 3:48am View    
please check this code which i've added
<authentication mode="Windows">
<identity password="password" username="domainname\username" impersonate="True">

<authorization>

<allow users="*"> <!-- Allow all users -->
sanjayv.gade 21-Nov-11 4:32am View    
thanx dude.....