如何检查每个网页中的会话 [英] how to Check the Sessions in each webPages

查看:96
本文介绍了如何检查每个网页中的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在特定页面正在打开的另一个网页中复制Url时,我遇到了一个严重的问题.
它不检查新网页中的会话..
我想避免在我的网页中出现这种情况

请帮助我

谢谢你
Sushil Dharmar

I have an serious Problem when i am Copying the Url in another webPage that Specific Page is opening..
Its not checking the Sessions in the new Web Pages..
I want to avoid such Things in my Web Pages

Kindly Help Me

Thanking you
Sushil Dharmar

推荐答案

如果您必须在所有页面中检查某些会话变量,那么也许可以在global.asax文件中的AcquireRequestState事件中执行此操作.在这里,您可以检查会话变量是否存在,如果不存在,则可以将用户推送到默认页面.
If you have to check for some session variable in all the pages then perhaps you can do this in AcquireRequestState event in global.asax file. here you can check if the session variable exist or not, if not then you can push the user to a the default page.
void Application_AcquireRequestState(object sender, EventArgs e)
{
  //Session is Available here
  HttpContext context = HttpContext.Current;
  if(context.session["value"] == null)
  {
    //redirect to default page
  }
}


另外,您需要检查正在使用的会话变量何时被杀死.很有可能它可能不会被杀死,因此只需复制URL即可打开页面.


Also, You need to check that when is this session variable that you are using is getting killed. chances are that it might not be getting killed and thus simply copying the URL is opening the page.


苏希尔,

您需要利用OOPS技术.做一件事,创建一个派生自system.web.ui.page的类,并编写Page Init方法的虚拟实现,以检查会话变量是否已设置.如果未设置,则重定向到登录页面.

现在,在asp.net页面中,在页面类之后删除:system.web.ui.page",您只需要继承新创建的继承了页面类的类即可.

问候
帕旺
Hi Sushil,

You need to take advantage of the OOPS techniques. Do one thing create a class that derives from system.web.ui.page and write a virtual implementation of Page Init method that checks whether the session variable is set or not. If it is not set then redirect to the login page.

Now in your asp.net pages remove the ": system.web.ui.page" after the page class, you will just need to inherit the newly created class that has inherited page class.

Regards
Pawan


这篇关于如何检查每个网页中的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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