| |

VerySource

 Forgot password?
 Register
Search
View: 2601|Reply: 18

asp.net authentication problem with session

[Copy link]

2

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-9-28 09:00:02
| Show all posts |Read mode
Choose to use session as authentication
I wrote a special page checkLogin.aspx as authentication,
The code behind is
if (Session["adminName"] != null)
        {

        }
        else
        {
            Response.Redirect("login.aspx");
        }

Then call on each page that requires authentication
Server.Execute("checkLogin.aspx");The authentication can be completed, but there is a problem
Controls such as dropdownlist cannot be returned, indicating that the page code is wrong, remove it
Server.Execute("checkLogin.aspx"); turned to normal afterwards, I don't know why.

Except for a piece of code authentication for each page, there is no other method, such as writing as a function, to facilitate modification of the authentication content. There is no such example.
Reply

Use magic Report

2

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-9-28 09:15:01
| Show all posts
I’m new to learn, ask for advice humbly, please don’t laugh
Reply

Use magic Report

0

Threads

1

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-9-28 09:22:47
| Show all posts
Can I put it in init? I haven't developed a website for several years. There is a problem with it, please forgive me
Reply

Use magic Report

0

Threads

60

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 United States

Post time: 2020-9-28 09:30:01
| Show all posts
Except for a piece of code authentication for each page, there is no other method, such as writing as a function, to facilitate modification of the authentication content. There is no such example.

There are many methods, such as writing a base class PAGE, all pages inherit it, but beginners suggest that you use COOKIE to verify it, it is easy to grasp, and it is used in practice.
Reply

Use magic Report

2

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-9-28 14:00:01
| Show all posts
Can you give an example
Reply

Use magic Report

0

Threads

12

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-9-28 14:30:01
| Show all posts
If it is an application system, httpModle is recommended
Or write a page base class like3521565

But for beginners, you can use yours!

As for your question
Controls such as dropdownlist cannot be returned, indicating that the page code is wrong...
Can you elaborate?
Reply

Use magic Report

0

Threads

12

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-9-28 15:15:01
| Show all posts
Example
public class WebBasePage:System.Web.UI.Page
{
public void CheckAuth()
{
       if (Session["adminName"] == null)
        {
            Response.Redirect("login.aspx");
        }
}

}

Other pages
WebForm1: WebBasePage
....
//Call that function
Reply

Use magic Report

2

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-9-28 16:00:01
| Show all posts
== huh
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-9-28 16:15:01
| Show all posts
Don't use session authentication, session is easy to expire. Although you can set its expiration time in webconfig, it is still useless. In fact, it will expire after a few minutes, so using it for authentication is not advisable. Here ASP.NET comes with Form authentication is ideal, and it is very easy,
See http://www.dvbbs.net/tech/net/201602153972.asp
After setting here, you can get this username by using Page.User. Identity.Name on other pages
Reply

Use magic Report

2

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-9-28 16:45:01
| Show all posts
Use Server.Execute("checkLogin.aspx"); to verify that there is a problem with the linkage of the drop-down list, prompt
_theForm.EVENTTARGET is empty or not an object
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list