Hi,
I have a webbrowser control that navigates to sharepoint port.
How can i send credentials to webbrowser control, so i can navigate to the site with custom credentials?
Hi,
I have a webbrowser control that navigates to sharepoint port.
How can i send credentials to webbrowser control, so i can navigate to the site with custom credentials?
If you cannot send querystring you will have to fake data with post so that the site thinks that you come from their sign in page. This means that you will have to check their login form to check out names of their fields, then you can sign in like below. Please note that you their login form has action member.php and action=login (action is a hidden field which must be used aswell). The field for username is called username and the field for password is called password. This must be taken in account in order for their page to retrieve the data correctly
string postData = "username=Kurresmack&password=pw&action=login&url=/";
webBrowser1.Navigate("www.sweclockers.com/forum/member.php", "", System.Text.Encoding.UTF8.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");
if you authenticate using windows try this:
#region imports
[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser(string
lpszUsername, string lpszDomain, string lpszPassword,
int dwLogonType, int dwLogonProvider, ref
IntPtr phToken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto,
SetLastError = true)]
private static extern bool CloseHandle(IntPtr handle
);
[DllImport("advapi32.dll", CharSet = CharSet.Auto,
SetLastError = true)]
public extern static bool DuplicateToken(IntPtr
existingTokenHandle,
int SECURITY_IMPERSONATION_LEVEL, ref IntPtr
duplicateTokenHandle);
#endregion
#region logon consts
// logon types
const int LOGON32_LOGON_INTERACTIVE = 2;
const int LOGON32_LOGON_NETWORK = 3;
const int LOGON32_LOGON_NEW_CREDENTIALS = 9;
// logon providers
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_PROVIDER_WINNT50 = 3;
const int LOGON32_PROVIDER_WINNT40 = 2;
const int LOGON32_PROVIDER_WINNT35 = 1;
#endregion
And then for "signing in" use this:
IntPtr token = IntPtr.Zero;
bool isSuccess = LogonUser("username", "domain", "password",
LOGON32_LOGON_NEW_CREDENTIALS,
LOGON32_PROVIDER_DEFAULT, ref token);
using (WindowsImpersonationContext person = new WindowsIdentity(token).Impersonate())
{
//do your thing
person.Undo();
}
It depends on the authentication method used by the server. For form authentication you just need to simulate a form post. But most likely the site is using integrated Windows authentication and you need to implement IAuthenticate(Ex) Or impersonate via LogonUser.