Solved

ASP.Net / C# - How to pass HTML form variables to a Login page

Posted on 2007-11-13
12
7,360 Views
Last Modified: 2010-08-05
I need to pass HTML form variables to a Login ...
the format is like this... how in C# can i do this so the 'target' page is submitted? What's the best approach?
Thanks

<html>
<form name="Login" METHOD="POST"  ACTION="https://www.Website/LoginControl.asp">
<input type="hidden" name="user" VALUE="ABC" size="15" maxlength="15">
<input type="hidden" name="password" VALUE="12345" size="15" maxlength="15">
<input type="submit" name="B1" value="SUBMIT">
</form>
</html>
0
Comment
Question by:JElster
12 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 20276685
in the page load event of the target page, grab the values you are passing like so...

if (null != Request["user"] )
{string sUser = Request["user"].ToString();}
else
{ return; }  // no value so don't attempt to parse
if (null != Request["password"] )
{string sPassword = Request["password"].ToString();}
else
{ return; }  // no value so don't attempt to parse

If you are able to fill these values, you can then process them the same as if you had hit the login button on the form.
so...if you have values do something like the following to check the user
validateLogin(sUser, sPassword);

of course you need to have created the validateLogin() routine

hth

0
 
LVL 1

Author Comment

by:JElster
ID: 20276719
Hi.. I don't have 'access' to the target login page code... it's a commerical app.
thanks
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 20276734
I am not sure what you are looking for.

In .NET in general you would use

<asp:textbox id="user" />
for a visible input or

<asp:hiddenfield id="user" />
for a hidden field.

Then on the page code behind you would use

user.Text or user.Value to get the results (depending on which method you used)

That way you avoid using the Request object.

In general asp.net pages post to themselves unless you enable cross-page posting.  but there is often not a need for this in a login page.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 16

Expert Comment

by:anoyes
ID: 20276787
I assume there's an existing login page that you're trying to replace?  Is the existing page a .html page, or a .aspx page?  If it's a .aspx page it may not be as easy to replace as just making a new .html page and pointing to that instead.  Can you give me some more info about what you're doing and how you're trying to go about doing it?
0
 
LVL 1

Author Comment

by:JElster
ID: 20276832
I'm trying to implement a 'silent login' that accepts the enclosed html form values...
I have no control over the 'target' login page... it just accepts   username, & password...
I want to automate the login from another page... pass the user and password to the login page and 'hit' submit... thanks
0
 
LVL 16

Expert Comment

by:anoyes
ID: 20276984
I can't think of any way to do that without modifying the 'target' login page somewhat based on how you've described it.  I would imagine this may have something to do with security so that a page can't make a user 'click' on something they did not intend to.  Is the target login page a .aspx page?
0
 
LVL 1

Author Comment

by:JElster
ID: 20316827
Please refund my points.. thanks
0
 
LVL 1

Accepted Solution

by:
JElster earned 0 total points
ID: 20316892
It's an asp page.. it's a commecial application / login in page.
I was able to do it with the following code...


            RemotePost myremotepost = new RemotePost();
            myremotepost.Url = "https://www.Website/LoginControl.asp";
            myremotepost.Add("LoginKey", "xyz");
             myremotepost.Add("usercode", _usercode);
            myremotepost.Add("password", _Password);
           
            myremotepost.Post();



 public class RemotePost
    {
        private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
        public string Url = "";
        public string Method = "post";
        public string FormName = "signinForm";
        public void Add(string name, string value)
        {
            Inputs.Add(name, value);
        }
        public void Post()
        {
            System.Web.HttpContext.Current.Response.Clear();

            System.Web.HttpContext.Current.Response.Write("<html><head>");

            System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
            System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
            for (int i = 0; i < Inputs.Keys.Count; i++)
            {
                System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
            }
            System.Web.HttpContext.Current.Response.Write("</form>");
            System.Web.HttpContext.Current.Response.Write("</body></html>");

            System.Web.HttpContext.Current.Response.End();
        }
    }
0
 
LVL 1

Expert Comment

by:Vee_Mod
ID: 20339117
Closed, 350 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question