Success!
In fact, I am only interested in winform technology, but now I have discovered that ASP. NET C # Web technology is becoming increasingly important!
As a result, I started to get started with what I know, especially some of the simplest things. I searched the internet for a long time. It's not too messy, that's not clear!
For example, if the session is okay, I don't know what the guys on the Internet are talking about?
Maybe I am too stupid! They really cannot understand their stuff!
So I decided to study it myself. It took a little time this afternoon and the results were as follows:
(1) In the load. aspx. CS file:
Public class myuser
{
Public myuser ()
{
}
Private string name;
Public string name
{
Get
{
Return name;
}
Set
{
Name = value;
}
}
}
// Note the class of the user object to which the myuser code logs in
// I wrote it in the load. aspx. CS file: but not in the load class, but in the same namespace
(2) In the load. aspx. CS file:
Protected void button#click (Object sender, eventargs E)
{
Try {
If (textbox1.text = "shigaofei" & textbox2.text = "123456") // here we use a hard verification to demonstrate that we will not connect to the database.
{
Myuser = new myuser ();
Myuser. Name = textbox1.text. Trim ();
This. session ["user"] = myuser; // Save the object
Server. Transfer ("loadsuccess. aspx ");
}
Else
{
Label1.text = "incorrect account or password ";
}
}
Catch
{
Label1.text = "An error occurred! ";
}
}
(3) In the loadsuccess. aspx. CS file:
Protected void page_load (Object sender, eventargs E)
{
Multiview1.activeviewindex = 0;
Label label1 = new label ();
Myuser my = new myuser ();
My = (myuser) session ["user"]; // retrieve the object in the session here, convert it to the myuser type, and assign it to the my object
Label1.text = "Welcome to here! "+ My. Name; // you can use my object to do things!
View1.controls. Add (label1 );
}
That's all.
This article is intended for beginners like me!