Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

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

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>
Avatar of Daniel Reynolds
Daniel Reynolds
Flag of United States of America image

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

Avatar of JElster

ASKER

Hi.. I don't have 'access' to the target login page code... it's a commerical app.
thanks
Avatar of mrichmon
mrichmon

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.
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?
Avatar of JElster

ASKER

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
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?
Avatar of JElster

ASKER

Please refund my points.. thanks
ASKER CERTIFIED SOLUTION
Avatar of JElster
JElster
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Closed, 350 points refunded.
Vee_Mod
Community Support Moderator