473,803 Members | 3,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?aktio n=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(o bject sender, System.EventArg s e)

{

string postdata;

WebClient page = new WebClient();

CredentialCache cache = new CredentialCache ();

CookieContainer ccContainer = new CookieContainer ();

ASCIIEncoding encoding = new ASCIIEncoding() ;

HttpWebRequest request
=(HttpWebReques t)WebRequest.Cr eate("https://xxxx.xxxx.com/admin/login.asp");

request.AllowAu toRedirect = false;

request.Method = "POST";

request.Content Type = @"applicatio n/x-www-form-urlencoded";

request.UserAge nt = "Mozilla/4.0 (compatible;" +

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

request.CookieC ontainer = new CookieContainer ();

postdata = "?aktion=login& username="+
HttpUtility.Url Decode("massimi liano.del.vita" ) + "&password= " +
HttpUtility.Url Decode("miami") +

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

request.Credent ials = new NetworkCredenti al("xxxx","xxxx ");

request.CookieC ontainer.Add(cc Container.GetCo okies(new
Uri("https://xxxx.xxxxx.com/admin/login.asp"));

byte[] buf = encoding.GetByt es(postdata);

request.Content Length = buf.Length;

Stream str = request.GetRequ estStream();

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

str.Close();

HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

if(request.Have Response)

{

Stream str2 = response.GetRes ponseStream();

StreamReader strReader = new StreamReader(st r2);

txtHtml.Text = strReader.ReadT oEnd().Trim();

string result = strReader.ReadT oEnd();

}

}

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

I solved with this code :
private void Button1_Click(o bject sender, System.EventArg s e)

{

Encoding enc = Encoding.GetEnc oding(1252);

ASCIIEncoding asciiEnc = new ASCIIEncoding() ;

Encoding ascii = Encoding.ASCII;
string UN = txtUsername.Tex t;

string PW = txtPass.Text;

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

string url = "https://xxx.xxx.com/admin/login.asp?aktio n=login&usernam e="+

UN+"&password=" +PW

+"&dest=/admin/tracking/queryresults.as p&qs=selectquer y"+
HttpUtility.Url Encode(sql, System.Text.Enc oding.GetEncodi ng("ISO-8859-1"));

txtURI.Text = url;

HttpWebRequest request =(HttpWebReques t)WebRequest.Cr eate(url);

request.Content Type = "applicatio n/x-www-form-urlencoded";

request.UserAge nt = "Mozilla/4.0 (compatible;" +

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

request.CookieC ontainer = new CookieContainer ();

try

{

HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

if(request.Have Response)

{

if(response.Con tentEncoding.Le ngth > 0)

{

enc = Encoding.GetEnc oding(response. ContentEncoding );

}

StreamReader strReader = new StreamReader(re sponse.GetRespo nseStream(),enc );

txtHtml.Text = strReader.ReadT oEnd().Trim();

string result = strReader.ReadT oEnd();

strReader.Close ();

response.Close( );

}

}

catch(WebExcept ion 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 =
(HttpWebRespons e)request.GetRe sponse(); 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
1465
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 spawn separate web windows leaving the menu page in the background. Common to all of these pages I am using authentication. The authentication function is as follows;
1
2371
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 Secure/DumpSearch.asp, line 700 Function AuthCheckT How can I get this to work?
2
7578
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 the VB program on that same machine, I can view the ActiveX control fine. He is using Citrix. The same ActiveX controls can be viewed on other machines. When trying to view 1 of the ActiveX control, he got an error "Visual Basic Run-time redist...
2
1279
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 should get a msg saying that they must logon, otherwise I wanted to place the username in label1.text. The .aspx page is on a IIS5 server with Scripts & Executables enabled. The error appears on line 3, char 9. Expected: ';' Can anyone spot what...
0
977
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 (the one running active directory) to make life easier. So, I've installed Framework 1.1, I've copied the directory, I've made it an Application, disabled Anonymous access. Web.Config's authorisation setting is set to "Windows".
4
3252
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 using server.transfer. Could this be causing a problem? Thanks, Tom
2
1430
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 logoff button which does another Response.Redirect(main url); Here is the issue, I am able to browse back to that page and the data is still populated and visible. How can I clear the cache for that page? I have tried: Response.Expires = 0;...
1
1590
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 submit of a logon web page using http? Wireless strikes me as the greatest risk. 3) Have you used http or https for Logon.aspx pages and why? 4) Anyone know if IIS on Windows Server 2003 has https built in? Easy or hard to configure?
6
9894
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 which uses Windows Authentication Now my question is how do we pass these credentials to IIS in classic ASP? Would appreciate any help/pointers on this. Thanks in advance.
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9121
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.