(Fastest Database /license Free) : XML Database Read XML File
(Fastest Database /license Free) : XML Database Read XML File
Web Site Add New Item XML File In XML <?xml version="1.0" encoding="utf-8" ?> <books> <book> <id>1</id> <title>c#</title> <author>hj </author> </book> <book> <id>2</id> <title>vb</title> <author>hjk</author> </book> </books> In web Form Grid View protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml(MapPath("XMLFile.xml")); GridView1.DataSource = ds; GridView1.DataBind(); }
and our "OnlineUsers" global variable is decreased. To know more about ApplicationState and HttpApplicationState class visit this MSDN link: msdn2.microsoft.com/en-us/library/system.web.httpapplicationstate(VS.80).aspx NOTE: we are using Application.Lock and Application.Unlock methods to prevent multiple threads from changing this variable at the same time. By calling Application.Lock we are receiving exclusive right to change the values in Application state. But we must not forget to call Application.Unlock() afterwards. Step 2: In order for this to work correctly we need to enable sessionstate and configure its mode to InProc value (in our web.config file): <system.web> <sessionState mode="InProc" cookieless="false" timeout="20" /> </system.web> In-process mode stores session state values and variables in memory on the local Web server. It is the only mode that supports the Session_OnEnd event that we used previously. Timeout value (in minutes, not in seconds) configures how long our sessions are kept 'alive' - in other words here we set how long our users can be inactive before considered Offline. In this example timeout is set to 20 minutes, so while our visitors click on some links in our website at least once in a 20 minutes, they are considered online. If they do not open any pages on our website longer than 20 minutes, they are considered Offline, and their session is destroyed, so our online visitor counter is decreased by 1. (You can experiment with lower or higher values of Timeout settings to see what is the best for your website). Ok, so now we are done with configuration steps, let us see how to use this: To show number of online visitors/users on your ASPX page you can use this code: Visitors online: <%= Application["OnlineUsers"].ToString() %>
Next you could put this code snippet in you UserControl, or inside Asp.Net AJAX UpdatePanel control, and use Timer to refresh it in regular intervals without refreshing the whole page, but that is another story