Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

c# - Secure Login Or Login check in asp.net

I am new in asp, here my question is that i have a website with pages home, about, contact, and login. In this website user can login and then access the home page, on home page there is a grid view with master page. The problem is that user can access the home page without login, just edit the path in address bar. For example the login page path is

http://lolhost:54515/mastergridvie/Login.aspx

and user edit it

http://localhost:54515/mastergridvie/Home.aspx

so user can go on home page without login, How I can prevent this?

I know for this there use a session, but I have no idea how to and where create a session for this :( Please can anyone help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Create Session in login page like this.

Session["userid"]="something";

And After That Check in Every Page Load like This.

if(Session["userid"] == null)
{
  Response.Redirect("Login.aspx");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...