473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to view a page after logon...

Hi i'm writing some code that retrieve the html source code of an asp page.

The problem is that if i go directly to this page the browser redirect me to
a login page where are two textbox in a html form.

<form action="/admin/login.asp?aktion=login" method="POST" name="login">
<table border="2" align="center">
<tr>
<td>
<b>Username:</b>
</td>
<td>
<input class="basic" type="text" size="15" name="username">
</td>
</tr>
<tr>
<td>
<b>Password:</b>
</td>
<td>
<input class="basic" type="password" size="15" name="password">
</td>
<td>
<input class="basic" type="submit" name="enterbut" value="Enter">
<input type="hidden" name="dest" value="">
<input type="hidden" name="qs" value="">
</td>

if i write in the address bar the link
https://xxx.xxx.com/admin/login.asp?...in/Default.asp
i go in the default.asp page.

now...i write this code in c# but it doesn't work...in the txtHtml textbox
is shown always the html source of the login.asp page...
private void Button1_Click(object sender, System.EventArgs e)

{

string postdata;

WebClient page = new WebClient();

CredentialCache cache = new CredentialCache();

CookieContainer ccContainer = new CookieContainer();

ASCIIEncoding encoding = new ASCIIEncoding();

HttpWebRequest request
=(HttpWebRequest)WebRequest.Create("https://xxxx.xxxx.com/admin/login.asp");

request.AllowAutoRedirect = false;

request.Method = "POST";

request.ContentType = @"application/x-www-form-urlencoded";

request.UserAgent = "Mozilla/4.0 (compatible;" +

" MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";

request.CookieContainer = new CookieContainer();

postdata = "?aktion=login&username="+
HttpUtility.UrlDecode("massimiliano.del.vita") + "&password=" +
HttpUtility.UrlDecode("miami") +

"&dest=" + HttpUtility.UrlDecode("/admin/Default.asp");

request.Credentials = new NetworkCredential("xxxx","xxxx");

request.CookieContainer.Add(ccContainer.GetCookies (new
Uri("https://xxxx.xxxxx.com/admin/login.asp"));

byte[] buf = encoding.GetBytes(postdata);

request.ContentLength = buf.Length;

Stream str = request.GetRequestStream();

str.Write(buf,0,buf.Length);

str.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if(request.HaveResponse)

{

Stream str2 = response.GetResponseStream();

StreamReader strReader = new StreamReader(str2);

txtHtml.Text = strReader.ReadToEnd().Trim();

string result = strReader.ReadToEnd();

}

}

could u help me? tnx
Nov 15 '05 #1
1 1971
Lorenzo wrote:
[CUT]

I solved with this code :
private void Button1_Click(object sender, System.EventArgs e)

{

Encoding enc = Encoding.GetEncoding(1252);

ASCIIEncoding asciiEnc = new ASCIIEncoding();

Encoding ascii = Encoding.ASCII;
string UN = txtUsername.Text;

string PW = txtPass.Text;

string sql = txtSql.Text.Replace(" ","%20").Replace("\n","
").Replace("\r","");

string url = "https://xxx.xxx.com/admin/login.asp?aktion=login&username="+

UN+"&password="+PW

+"&dest=/admin/tracking/queryresults.asp&qs=selectquery"+
HttpUtility.UrlEncode(sql, System.Text.Encoding.GetEncoding("ISO-8859-1"));

txtURI.Text = url;

HttpWebRequest request =(HttpWebRequest)WebRequest.Create(url);

request.ContentType = "application/x-www-form-urlencoded";

request.UserAgent = "Mozilla/4.0 (compatible;" +

" MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)";

request.CookieContainer = new CookieContainer();

try

{

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if(request.HaveResponse)

{

if(response.ContentEncoding.Length > 0)

{

enc = Encoding.GetEncoding(response.ContentEncoding);

}

StreamReader strReader = new StreamReader(response.GetResponseStream(),enc);

txtHtml.Text = strReader.ReadToEnd().Trim();

string result = strReader.ReadToEnd();

strReader.Close();

response.Close();

}

}

catch(WebException wexc)

{

txtUrl.Text = wexc.Message;

}

}

but... often if i write an sql statement in txtSql textbox it appear correct
in txtURI textbox (if i cut & paste it in the explorer address bar worked
well) but the HttpWebResponse response =
(HttpWebResponse)request.GetResponse(); give me an error of type 400 (remote
server error)...

Why?
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: William E Hatto | last post by:
Hi 1 and all, I have an asp application/web site that uses a logon page then a page for the menus and separate asp pages for all the options in the menus. The options listed in the menu's...
1
by: William E Hatto | last post by:
My thanks to Nathan for the code below, but it does not work. I get the following error; Error Type: Microsoft VBScript compilation (0x800A03EA) Syntax error /dev/development/WAN RCI...
2
by: Fie Fie Niles | last post by:
This one XP machine (with IE 6) is having a problem viewing any ActiveX controls (created on VB6) on the Internet Explorer browser. I put the same ActiveX control in a VB program, and when I run...
2
by: James | last post by:
Hello All, I'd like to get the network username by using the Request.ServerVariables("AUTH_USER"). The code I've got is pretty simple yet I am getting error. If the user does not logon they...
0
by: Dan Nash | last post by:
Hi I was running a test server (xp pro) on my machine running an ASP.NET application, but cos of all the thoughts people have had re computer name, thought id move it to my Windows 2000 server...
4
by: tshad | last post by:
I have a logon page that is getting the previous page in its return URL ("logon.aspx?returnURL=A.aspx") where A.aspx is the page that called B.aspx. It should have B.aspx. I am calling B.aspx...
2
by: Terry | last post by:
Hello everyone, I created a logon page using C# ASPX, I have the user logon and if logon information is correct I do a Response.Redirect(url); On the second page it displays data and I have a...
1
by: Randall Parker | last post by:
1) What sorts of scenarios make the possibility of sniffing out a password a higher risk? 2) Do packets travel unencrypted over 802.11 wireless? Is it easy to sniff such packets and catch a...
6
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, We have a requirement where we have to develop a custom Login Page which will accept user's NT credentials ( Username , password, domain name). This then needs to be passed to a website...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.