Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
How can I make a sign-in program in ASP.net wherein the entered username will be saved in a variable and will be passed into another webform?

I've tried to used this code:
Response.Redirect("todo.aspx?id= "+TextBox1.Text+" ");

and this, in another webform:
string str = Request.QueryString["idname"].ToString();

but it didn't function.
Posted

First of all, try not to pass the user name password combination (especially password) around.
Passing the password in the url would be the biggest risk your system could possibly have.

Passing parameters is explained here[^].

Use UrlEncode[^] to encrypt any url parameters you pass around.
 
Share this answer
 
Comments
Espen Harlinn 10-Feb-13 18:41pm    
5'ed!
Abhinav S 11-Feb-13 0:29am    
Thank you Espen.
fjdiewornncalwe 11-Feb-13 12:02pm    
+5.
Abhinav S 11-Feb-13 21:41pm    
Thank you.
Follow the answers given by Abhinav S and Sergey Alexandrovich Kryukov, which says not to pass the username and password in between pages as it is security threat and will create hole to your application.

Use Sessions
So, try to save in session so that you can access them in any page till user signs out, which will be secure.

Refer Prize winner article - Exploring Session in ASP.NET[^] to explore about sessions in details. Storing and retrieving values from Session[^] section of the article will give you simple example how to do it.

Problem in your code
Now coming to your code, the problems are as follows...

1. You are sending the QueryString named as "id", but trying to get it as "idname", for which you are not getting the data. (All underlined)
C#
Response.Redirect("todo.aspx?id= "+TextBox1.Text+" ");

string str = Request.QueryString["idname"].ToString();


2. There is one space after "id" and "+" sign in the QueryString, which is also create problem.
And there are extra "+" and quotes after the TextBox1.Text, which are not required. (All underlined).
C#
Response.Redirect("todo.aspx?id= "+TextBox1.Text+" ");


So, the code will be like below...
C#
Response.Redirect("todo.aspx?id=" + HttpUtility.UrlEncode(TextBox1.Text));
string str = Request.QueryString["id"].ToString();


Thanks...
 
Share this answer
 
Comments
jmpapa 9-Feb-13 22:07pm    
Thanks for all the respond. I'm already using sessions now. And it works fine.
Great news...
Carry on the good work. :)
Espen Harlinn 10-Feb-13 18:41pm    
5'ed!
Thanks @Espen Harlinn.
First thing you have to learn: never store a password anywhere, never pass it through the network using insecure protocol. You may ask "how to authenticate then?" This is the whole idea. You never need it for authentication. Disagree? Cannot believe that? Keep reading.

Please see my past answers:
storing password value int sql server with secure way[^],
Decryption of Encrypted Password[^],
i already encrypt my password but when i log in it gives me an error. how can decrypte it[^],
TCP Connection with username and password[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 10-Feb-13 18:41pm    
5'ed!
Sergey Alexandrovich Kryukov 10-Feb-13 18:50pm    
Thank you, Espen.
—SA
Abhinav S 11-Feb-13 0:30am    
5. Good links IMO.
Sergey Alexandrovich Kryukov 11-Feb-13 1:27am    
Thank you, Abhinav.
—SA
fjdiewornncalwe 11-Feb-13 12:02pm    
My 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900