In my project, I want once a user logs in, one or more of the pages be disabled for him, if he has visited them once and is trying to re-visit them. For that a message should display : You have already visited the page for the day.
How is this possible? I don't know how to keep the entire page disabled for the user, after checking the condition...
1) create a time check in for a user, i mean store some flag in DB or in a file if he has visited a particular page.
2) for every page, where you want user should be stopped viewing the page and it should come in disable mode, you must need to create a CSS, one javascript function and a DIV tag that will open at the front of the screen and stop him viewing the page. this
is all about logical answer, give me some time I'll be back with the code.
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Store the page name and the user name in a database along with the date the user visited the page and when the page loads, check the database to see if there is an entry for that page and user for the current date. If there is an entry, redirect them to
another page that displays the message.
1. Create a table in DB e.g. URLtracker with columns like URL, Username, timestamp
2. A method written in PaegLoad will check if any entry in the table matches with the following parameters -
a. Current URL, b. Username
If there is, then block the user from viewing the page or redirect to some other page.
If not, add an entry in URLTracker table with the current URL (with or without querystring, your call) and logged in user.
3. You can omit the above step if the user is not logged in.
Trust this helps!
Mihir,
Software Professional
http://www.mihirmone.com
1. Create a table in DB e.g. URLtracker with columns like URL, Username, timestamp
2. A method written in PaegLoad will check if any entry in the table matches with the following parameters -
a. Current URL, b. Username
If there is, then block the user from viewing the page or redirect to some other page.
If not, add an entry in URLTracker table with the current URL (with or without querystring, your call) and logged in user.
3. You can omit the above step if the user is not logged in.
I already have a table in the database which checks the login details. It has columns: LoginID, Login Time, Logout Time, ClientIP, Entry Date etc.
Hi, please use the code below for your purpose, to achieve this you just need to add main jquery file, that you can download from internet or it comes with VS2010, rest of the code is below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
public partial class SomeJunk_DisablePage_DisablePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) // here you can write your code to check user visits to show or hide the script
{
ClientScript.RegisterStartupScript(this.GetType(), "s", "Popup('Hello');", true);
}
}
}
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Marked as answer by coolpal9 on Apr 10, 2012 11:02 AM
coolpal9
Member
156 Points
520 Posts
How to keep a page disabled for a particular user?
Apr 10, 2012 06:41 AM|LINK
Hi,
In my project, I want once a user logs in, one or more of the pages be disabled for him, if he has visited them once and is trying to re-visit them. For that a message should display : You have already visited the page for the day.
How is this possible? I don't know how to keep the entire page disabled for the user, after checking the condition...
Can someone pl help me out..?
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 06:48 AM|LINK
it's possible, just follow below steps:
1) create a time check in for a user, i mean store some flag in DB or in a file if he has visited a particular page.
2) for every page, where you want user should be stopped viewing the page and it should come in disable mode, you must need to create a CSS, one javascript function and a DIV tag that will open at the front of the screen and stop him viewing the page. this is all about logical answer, give me some time I'll be back with the code.
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Mikesdotnett...
All-Star
154852 Points
19855 Posts
Moderator
MVP
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 06:48 AM|LINK
Store the page name and the user name in a database along with the date the user visited the page and when the page loads, check the database to see if there is an entry for that page and user for the current date. If there is an entry, redirect them to another page that displays the message.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Srikanth Kas...
Contributor
4289 Points
883 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 06:49 AM|LINK
Hi again, You can try the role based authentication.
http://www.codeproject.com/Articles/2905/Role-based-Security-with-Forms-Authentication
Srikanth Kasturi
Please "Mark As Answer" if my post serves purpose.
coolpal9
Member
156 Points
520 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 07:06 AM|LINK
Thanks all for your ideas. But I don't know how to execute them, so I will need your help for that.
Pl do help me out...
Srikanth Kas...
Contributor
4289 Points
883 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 07:27 AM|LINK
Sure we are here to help you out.
You can go through the articles pertaining to the role based authentication.
http://support.microsoft.com/kb/311495
http://www.codeproject.com/Articles/2905/Role-based-Security-with-Forms-Authentication
Let us know if you have stuck somewhere.
Srikanth Kasturi
Please "Mark As Answer" if my post serves purpose.
mihir.mone
Member
392 Points
115 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 07:29 AM|LINK
To follow the suggestions as per above,
1. Create a table in DB e.g. URLtracker with columns like URL, Username, timestamp
2. A method written in PaegLoad will check if any entry in the table matches with the following parameters -
a. Current URL, b. Username
If there is, then block the user from viewing the page or redirect to some other page.
If not, add an entry in URLTracker table with the current URL (with or without querystring, your call) and logged in user.
3. You can omit the above step if the user is not logged in.
Trust this helps!
Software Professional
http://www.mihirmone.com
coolpal9
Member
156 Points
520 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 07:44 AM|LINK
I already have a table in the database which checks the login details. It has columns: LoginID, Login Time, Logout Time, ClientIP, Entry Date etc.
Is this sufficient??
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 09:00 AM|LINK
Hi, please use the code below for your purpose, to achieve this you just need to add main jquery file, that you can download from internet or it comes with VS2010, rest of the code is below:
ASPX Markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisablePage.aspx.cs" Inherits="SomeJunk_DisablePage_DisablePage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="jquery-1.7.1.js" type="text/javascript"></script> </head> <body> <script type="text/javascript"> function Popup(msg) { setInterval(" $(\"#pop1\").show();", 100); } </script> <form id="form1" runat="server"> <div> <asp:Label ID="lblName" runat="server" Text="Name: "></asp:Label> <asp:TextBox ID="txtName" runat="server"></asp:TextBox> <div id="pop1" class="parentDisable"> <div id="popup"> You have visited this site more then once </div> </div> </div> </form> <style type="text/css"> .parentDisable { z-index: 1000; width: 100%; height: 736px; display: none; position: absolute; top: 0; left: 0; background-color: Gray; opacity: .4; /*color: #aaa;*/ filter: alpha(opacity=88); } #popup { /*width: 400px; height: 200px; margin: 150px 0px 0px 500px;*/ width: 100px; height: 70px; position: relative; vertical-align: middle; text-align: center; margin: 200px 0px 0px 600px; border: 1px solid white; color: #000; background-color: #fff; } </style> </body> </html>CodeBehind:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Threading; public partial class SomeJunk_DisablePage_DisablePage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) // here you can write your code to check user visits to show or hide the script { ClientScript.RegisterStartupScript(this.GetType(), "s", "Popup('Hello');", true); } } }Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
coolpal9
Member
156 Points
520 Posts
Re: How to keep a page disabled for a particular user?
Apr 10, 2012 10:29 AM|LINK
@Ashutosh Pathak
Thanks for the code. Do I need to add another form altogether to include the code? I need to disable just one or two pages on an attempt to re-visit.
Is it ok if I just add the relevant part of the code to an already existing page??