How to keep a page disabled for a particular user?http://forums.asp.net/t/1791020.aspx/1?How+to+keep+a+page+disabled+for+a+particular+user+Wed, 18 Apr 2012 10:48:09 -040017910204924128http://forums.asp.net/p/1791020/4924128.aspx/1?How+to+keep+a+page+disabled+for+a+particular+user+How to keep a page disabled for a particular user? <p>Hi,</p> <p>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.</p> <p>How is this possible? I don't know how to keep the entire page disabled for the user, after checking the condition...</p> <p>Can someone pl help me out..?</p> 2012-04-10T06:41:21-04:004924141http://forums.asp.net/p/1791020/4924141.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>it's possible, just follow below steps:</p> <p>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.</p> <p>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.</p> 2012-04-10T06:48:47-04:004924142http://forums.asp.net/p/1791020/4924142.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>Store the page name and the user name in a database &nbsp;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.</p> 2012-04-10T06:48:58-04:004924143http://forums.asp.net/p/1791020/4924143.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>Hi again, You can try the role based authentication.</p> <p><a href="http://www.codeproject.com/Articles/2905/Role-based-Security-with-Forms-Authentication">http://www.codeproject.com/Articles/2905/Role-based-Security-with-Forms-Authentication</a></p> 2012-04-10T06:49:02-04:004924173http://forums.asp.net/p/1791020/4924173.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>Thanks all for your ideas. But I don't know how to execute them, so I will need your help for that.</p> <p>Pl do help me out...</p> 2012-04-10T07:06:45-04:004924208http://forums.asp.net/p/1791020/4924208.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>Sure we are here to help you out.&nbsp;</p> <p>You can go through the articles pertaining to the role based authentication.&nbsp;</p> <p><a href="http://support.microsoft.com/kb/311495">http://support.microsoft.com/kb/311495</a></p> <p><a href="http://www.codeproject.com/Articles/2905/Role-based-Security-with-Forms-Authentication">http://www.codeproject.com/Articles/2905/Role-based-Security-with-Forms-Authentication</a></p> <p>Let us know if you have stuck somewhere.</p> 2012-04-10T07:27:30-04:004924210http://forums.asp.net/p/1791020/4924210.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>To follow the suggestions as per above,</p> <p>1. Create a table in DB e.g. URLtracker with columns like URL, Username, timestamp<br> 2. A method written in PaegLoad will check if any entry in the table matches with the following parameters - <br> a. Current URL, b. Username <br> If there is, then block the user from viewing the page or redirect to some other page. <br> If not, add an entry in URLTracker table with the current URL&nbsp;(with or without querystring, your call) and logged in user. <br> 3. You can omit the above step if the user is not logged in. <br> <br> Trust this helps!</p> 2012-04-10T07:29:00-04:004924246http://forums.asp.net/p/1791020/4924246.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>mihir.mone</h4> <p></p> <p>1. Create a table in DB e.g. URLtracker with columns like URL, Username, timestamp<br> 2. A method written in PaegLoad will check if any entry in the table matches with the following parameters - <br> a. Current URL, b. Username <br> If there is, then block the user from viewing the page or redirect to some other page. <br> If not, add an entry in URLTracker table with the current URL&nbsp;(with or without querystring, your call) and logged in user. <br> 3. You can omit the above step if the user is not logged in. <br> <br> </p> </blockquote> <p></p> <p>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.</p> <p>Is this sufficient??</p> 2012-04-10T07:44:49-04:004924434http://forums.asp.net/p/1791020/4924434.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>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:</p> <p>ASPX Markup:</p> <pre class="prettyprint">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;DisablePage.aspx.cs&quot; Inherits=&quot;SomeJunk_DisablePage_DisablePage&quot; %&gt; &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head runat=&quot;server&quot;&gt; &lt;title&gt;&lt;/title&gt; &lt;script src=&quot;jquery-1.7.1.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script type=&quot;text/javascript&quot;&gt; function Popup(msg) { setInterval(&quot; $(\&quot;#pop1\&quot;).show();&quot;, 100); } &lt;/script&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:Label ID=&quot;lblName&quot; runat=&quot;server&quot; Text=&quot;Name: &quot;&gt;&lt;/asp:Label&gt; &lt;asp:TextBox ID=&quot;txtName&quot; runat=&quot;server&quot;&gt;&lt;/asp:TextBox&gt; &lt;div id=&quot;pop1&quot; class=&quot;parentDisable&quot;&gt; &lt;div id=&quot;popup&quot;&gt; You have visited this site more then once &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;style type=&quot;text/css&quot;&gt; .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; } &lt;/style&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p></p> <p>CodeBehind:</p> <pre class="prettyprint">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); } } }</pre> <p></p> 2012-04-10T09:00:18-04:004924641http://forums.asp.net/p/1791020/4924641.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>@Ashutosh Pathak</p> <p>Thanks for the code. Do&nbsp;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.</p> <p>Is it ok if I just add the relevant part of the code to an already existing page??</p> 2012-04-10T10:29:57-04:004924658http://forums.asp.net/p/1791020/4924658.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>yes ofcourse, i've just created a dummy page, take out the javascript portion and CSS portion, dont forget to copy the two div elements. you need to copy all these things to all the pages you want to disable. and in code behind you just call the method as im calling based on your condition.</p> 2012-04-10T10:39:59-04:004924696http://forums.asp.net/p/1791020/4924696.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>Thanks a lot! Its working! i ran code without checking conditions.</p> <p>How shall I check for the condition? I am not getting it. I want the page to be disabled:</p> <p>1. when the page has been already visited for the day and &quot;submit&quot; button has been clicked</p> <p>2. on certain days (like weekends) it should be disabled&nbsp;</p> 2012-04-10T10:55:56-04:004924752http://forums.asp.net/p/1791020/4924752.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>in such cases you need to store the values or set a flag value in your database for the day, if the flag value is up for that user in your database, then in page load you will disable the page. to be precise you also need to create a database schema for user wise day wise flag entry,.</p> 2012-04-10T11:19:53-04:004924808http://forums.asp.net/p/1791020/4924808.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>I already have the list of holidays in my database. But the point is that I don't know how to use them at this moment, as a condition to disable the page...?</p> <p>I fetch the holidays through stored procedures. But here I don't know how to code for the condition?</p> 2012-04-10T11:41:28-04:004924835http://forums.asp.net/p/1791020/4924835.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>its pretty simple, just check the current day using datetime.now. later iterate with the list of holidays that you got in a dataset or datareader to search the entry of current date, if you get any date like such, call the Popup method and break the code from there.</p> 2012-04-10T11:55:17-04:004924845http://forums.asp.net/p/1791020/4924845.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>Yes I have the holidays in a DataSet.</p> <p>Do you mean that by showing:</p> <p>DataSet ds;</p> <p>if(ds.System.DateTime.Now)</p> <p>{}</p> <p>something like this the condition will be met?</p> <p>Can you pl help me out in the code?</p> 2012-04-10T12:01:04-04:004924895http://forums.asp.net/p/1791020/4924895.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>i think you can use code like below:</p> <pre class="prettyprint">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Threading; using System.Data; 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 { DateTime _dt = DateTime.Now; DataSet _dset = LoadDataSet(); foreach (DataRow _dr in _dset.Tables[0].Rows) { DateTime dtRow = Convert.ToDateTime(_dr[&quot;Holiday&quot;].ToString()); if (dtRow.Month == _dt.Month &amp;&amp; dtRow.Day == _dt.Day &amp;&amp; dtRow.Year == _dt.Year) { ClientScript.RegisterStartupScript(this.GetType(), &quot;s&quot;, &quot; Popup('Hello');&quot;, true); } } } } public DataSet LoadDataSet() { DataSet _dset = new DataSet(); _dset.Tables.Add(new DataTable()); _dset.Tables[0].Columns.Add(&quot;Holiday&quot;, typeof(DateTime)); for (int i = 0; i &lt; 6; i&#43;&#43;) { DataRow _dr = _dset.Tables[0].NewRow(); _dr[&quot;Holiday&quot;] = DateTime.Now.AddDays(i); _dset.Tables[0].Rows.Add(_dr); } return _dset; } }</pre> <p></p> 2012-04-10T12:21:23-04:004924919http://forums.asp.net/p/1791020/4924919.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>Thanks!</p> 2012-04-10T12:31:27-04:004926072http://forums.asp.net/p/1791020/4926072.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? &lt;div&gt; <p>Got it run!</p> &lt;/div&gt; 2012-04-11T05:08:59-04:004926207http://forums.asp.net/p/1791020/4926207.aspx/1?Re+How+to+keep+a+page+disabled+for+a+particular+user+Re: How to keep a page disabled for a particular user? <p>@Ashutosh Pathak</p> <p>The code works but only once. When I execute it again for checking conditions, it again restricts me from viewing...</p> <p>How to solve this problem?</p> 2012-04-11T06:24:37-04:00