How can i change session when open url in another tab in asp.net

时间秒杀一切 提交于 2019-12-05 06:43:00

问题


I am developing one web application in asp.net. I am opening my all pages on pop up window. I want to expire my session or change the session value when someone copy the url and paste it into another tab. How can i implement it ? Please help me out.


回答1:


A simple way would be to check Request.UrlReferrer. The Referrer would be empty if the user copy pastes a URL.

A couple of points you should consider before using this:

  1. Provide exceptions for any pages that can be directly entered by the user. For e.g. the login page or a page that can be bookmarked
  2. I believe a pop can be opened from Javascript, without a referrer. Make sure your existing code is not using this method to open a pop up.

For a generic way to determine if the user has opened a new tab, see here




回答2:


I have solved this problem by using this

   string referer = Request.ServerVariables["HTTP_REFERER"];
        if (string.IsNullOrEmpty(referer))
        {
            Response.Redirect("../Index.htm");
        }


来源:https://stackoverflow.com/questions/7238560/how-can-i-change-session-when-open-url-in-another-tab-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!