Currently we are having an (ASP.NET) Order managemnet application developed using MVC3 architecture. In that to show certificates we redirect to a third party website which contains .Jsp pages. User can enter his credentials and login. This redirection is done through J query.
Now as per new requirement, user wants to login third party website with our website credentials only. I checked for cookies, input parameters on .Jsp page, but not found some needful data.
After goggling implemented this by using WebHttpRequest & WebClient classes in C#. Also used POST method.
In case of WebHttpRequest blank values are passed and login function is getting called and displaying blank field messages (though I have passed correct values.).
And in case of WebClient classes, not getting any error but unable to login.
Can anybody have implemented this anywhere ? How we can pass login parameters to .Jsp pages from Asp.Net application.
Waiting for you reply. Thanks.
You can send your reply - abhijeet.vaikar99@gmail.com
Please see below code, which I have implemented as of now.
private string LoginESABUsingWebClient()
{
string submitButton = "Login";
submitButton = System.Web.HttpUtility.UrlEncode(submitButton);
try
{
string userName = "wasim";
string password = "Pass@0-0";
Users user = new Users();
user.UserName = userName;
user.Password = password;
string uriString = "http://test-esab-onlinelb.eu.esab.org/Home/Login";
string postString = "userName=" + userName + "&password=" + password + "&loginButton=" + submitButton;
Request.Cookies.Add(new HttpCookie("userCountry", "GB"));
Request.Cookies.Add(new HttpCookie("userLanguage", "EN"));
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
webClient.Credentials = new NetworkCredential(userName, password);
byte[] postData = Encoding.ASCII.GetBytes(postString);
byte[] responseData = webClient.UploadData(uriString, "POST", postData);
string srcString = Encoding.UTF8.GetString(responseData);
return srcString;
}
catch (WebException ex)
{
return ex.Message;
}
}
private string LoginThroughWebHttpRequest()
{
string userName = "wasim";
string password = "Pass@0-0";
Users user = new Users();
user.UserName = userName;
user.Password = password;
string urlSignin = "http://test-esab-onlinelb.eu.esab.org/Home/Login";
Uri uriSignin = new Uri(urlSignin);
String postData = "";
postData = "userName=" + userName + "&password=" + password;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
HttpWebRequest webReq;
HttpWebResponse webResp;
CookieContainer cookies = new CookieContainer();
String responseString = "";
try
{
webReq = (HttpWebRequest)WebRequest.Create(urlSignin);
webResp = (HttpWebResponse)webReq.GetResponse();
cookies.Add(webResp.Cookies);
string sessionCookie = webResp.Headers["Set-Cookie"];
responseString = new StreamReader(webResp.GetResponseStream()).ReadToEnd();
string respCookie = sessionCookie.Substring(0, sessionCookie.IndexOf(';'));
char[] separator = { '=' };
string[] cookieValues = respCookie.Split(separator);
cookies.Add(new Cookie(cookieValues[0], cookieValues[1], "/", "test-esab-onlinelb.eu.esab.org"));
cookies.Add(new Cookie("userCountry", "GB", "/", "test-esab-onlinelb.eu.esab.org"));
cookies.Add(new Cookie("userLanguage", "EN", "/", "test-esab-onlinelb.eu.esab.org"));
webReq = (HttpWebRequest)WebRequest.Create(urlSignin);
webReq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webReq.Referer = urlSignin;
webReq.KeepAlive = true;
webReq.Method = "POST";
webReq.Credentials = new NetworkCredential(userName, password);
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.ContentLength = 0;
webReq.AllowAutoRedirect = false;
webReq.CookieContainer = cookies;
webReq.Timeout = 30000;
webReq.ReadWriteTimeout = 60000;
webResp = (HttpWebResponse)webReq.GetResponse();
responseString = new StreamReader(webResp.GetResponseStream()).ReadToEnd();
webResp.Close();
return responseString;
}
catch (Exception ex)
{
throw ex;
}
}