如何在asp.net中使用会话 [英] how to use sessions in asp.net

查看:82
本文介绍了如何在asp.net中使用会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



i我在asp.net中使用c#创建了一个登录页面,其中密码和用户名需要使用

但是问题是我的管理页面是使用此页面的网址直接打开的,没有任何

用户名和密码。我希望它永远不会重定向到管理面板使用网址没有passowrd

所以请帮助我...



谢谢你阿里。

解决方案

您首先要使用的是表单身份验证。 [ ^ ]



一旦你有了这个,那么任何时候用户试图访问任何网址,如果他们有首先没有登录,他们将被重定向到登录页面。



作为验证用户身份的一部分,您可能希望将用户ID存储到会话变量中这样你的其他页面就可以根据需要使用它。


试试这个,它会帮助你。

在你的登录页面。检查id和Pwd的身份验证后。创建会话..



会话[pno] = txtUserid.Text; 





现在在adminPage_load活动中查看此会话。



  if (( string )会话[  pno] ==  null  ||( string )会话[  pno] == < span class =code-string> 
{
Server.Transfer( SessionExpire.aspx);
}





sessionExpire.aspx是一个页面,仅提供有关会话到期的消息以及重新登录用户的选项。


HI,

i am new in asp.net using c# i created a login page in which password and username is requierd
but the problem is that my admin page is directly open using the url of this page with out any
username and password. i want it will never redirect to admin panel using urls without passowrd
so please help me...

thank you ali.

解决方案

What you first want to use is called Forms Authentication.[^]

Once you have that then anytime a user tries to get to any url, if they have not logged in first they will get redirected to the login page.

As part of authenticating the user you'll want to store, perhaps the userid, into a session variable so that your other pages can then use it as needed.


Try this, it will help you.
in your login page. After Checking Authentication of id and Pwd. Create session..

Session["pno"] =txtUserid.Text;



now in your adminPage_load event check this session.

if ((string)Session["pno"] == null || (string)Session["pno"] == "")
       {
           Server.Transfer("SessionExpire.aspx");
       }



sessionExpire.aspx is a page that only gives message about expiry of session and option to relogin the user.


这篇关于如何在asp.net中使用会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆