my problem is follow:
I have an auctioneer site, in which many different objects will be auctioneerd.
My problem is very simple to clear for an more experience user I thinK. How I can handle business and database logic without opened a site or them?
My problem is to say directly, if nights at 3 no user is on the site, the winner (e.g.) must be set - if a page is opened or not.
So I need some kind of "every 2 seconds, do this method" - without opened a site.
My idea was a sepereate application which uses the same business and database-layer as the asp.net page and let this run at the server. Is that a good or bad idea?
The separate process (scheduled app or Windows service) is the only reliable way you can achieve this.
Using the same BLL and DAL are exactly the right thing to do too.
Check out this article on windows services http://msdn.microsoft.com/en-us/library/aa984074(VS.71).aspx
To let every user query the database every 2 seconds would create unnecessary traffic on your site, which is not a good idea. (users tend to refresh the page many times just before the auction closes anyway)
My thoughts:
Add a date to the auction when it closes.
The last user that places a bid is always the winner, and you can't place bids after 3 am (the date the auction closes), so if you visit the site after 3 am (you can't place a bid and) the winning user is displayed. If somebody opens the site just before 3 am and places a bid after 3 am your business logic should check the date of the bid and deny it.. (also: users might live in different timezones so consider displaying the server time on your site).
Setting the date to 'now' would close the auction immediately.
You can also add javascript to refresh the page if your clock passes the hour or something like that. (or use the number of seconds left before the auction closes in a setTimeout function or metarefresh)
Related
I'm developing an online quiz site where the users can take tests (multiple choice). I have a requirement to put a timer on the test say if the maker of the test sets the time to 30min a timer would be placed on top of the page counting down the time, now i want to monitor the timer on the server side when it reaches to 00:00 the test would stop and the marks obtained is shown.
Solutions i have considered:
1) To use a JS plugin and upon its expiry do a location.href to some ActionResult that will end the test.
2) To create a session and clear it after the given time and before rendering each question check that session if it has expired or not.
My concern about using a javascript based solution is its robustness, i want to implement a server side solution. Please help me find the right path...
Regards.
When using the timer in the browser there is no way to verify that it is running as expected. User can disable javascript and get around your restrictions; heck they can even change your javascript. So relying solely on javascript is not an option.
The best solution is to validate postbacks on server side. You can use javascript on Client side to inform the user so that they are aware of how much time is left and server side to verify they have not gone over the time limit. If synchronization is required, then you can have the javscript ping back every so often to resynch the time.
Expanded Answer
The time of the start of the test should be on the server side. Whenever the user clicks begin test or other start buttton to begin their test. The server should note the current time - perhaps in a session or even in database.
The user should then be informed of the time remaining via javascript and expected end time. These are then updated whenever the user submits a question or perform another postback to the server.
The end time will be the fuzzy part. If the javascript does it's job correctly; you can inform the user their test has ended through this (or window.href etc). If the javascript is not worked; then the user will receive their notification whenever they next attempt to submit something to the server.
Either way, the user should clearly be informed that this is the expected end time, and how much time they have remaining on each page load.
in my asp.net form i want to show country flag along with current visitor count. when user visit our site from USA then USA flag count will be increase by one and when the same user close his browser or go to another site then count will be decrease. please give me the best logic to show current visitor count country wise along with country flag. need help. thanks
The biggest problem here is this - you can't rely on the event of closing the browser.
http://www.codeproject.com/Articles/58835/Window-Close-Event-of-Browser
However, you can try to get at least approximate results. In the article above you see how to react on these events. I'd use ajax to communicate with the server to increment/decrement the values as needed, updating the relevant parts of the page in the process. For storage, you can use database to store these values for instance.
Look here for more info on ajax with jquery in asp.net: http://www.simple-talk.com/dotnet/asp.net/ajax-basics-with-jquery-in-asp.net/ If it isn't enough for you, use google, there are plenty resources out there waiting for you.
As the title states, how can i stop two users from booking the same appointment time.
Example, two users logging, on there screen they can both see that a 1pm appointment is available. They both try to book themselves into that appointment time.
How can i stop this from happening and ensure only one user can book it, then refresh the screen to show the next available booking time to the other user.
Thanks.
That's a fairly classic use case. You can simply display the appointment plan at a specific time. That can remain static or you can set up a periodic process (for example, every five seconds) to update the plan with new information.
Then, when the user/operator decides to book a free timeslot, it tries to do an (atomic) update that will fail if someone else has slipped in (using primary key or some other unique constraint). The atomicity of the update operation guarantees that only one person can book the timeslot. If the update works, voila, you have your time booked.
If it fails, notify the user of that fact and then load up the new appointment plan.
Rinse and repeat until the user has their booking or they wander off, disgruntled.
I do not think that this is optimal. Why don't you opt for a first clicked/first served pattern ?
What may happen if you have 10 users or more viewing the same page ? A user viewing a page does not mean that he will click on a time slot. So IMHO wait for a user to REALLY click and then notify eventually other users that a time slot they are viewing has been booked (As it happens with StackOverFlow when somebody answers a question while you are answering)
I need to display how many users are browsing my site. The site is running on iis7, and we are using asp.net 3.5.
Is the number of active sessions a good way to go?
The number does not need to be very accurate.
No history is needed, I just want to know how many users are "online" right now, and display that on the page itself.
You can use Windows Performance counters for this (perfmon)
ASP.NET Applications > Sessions Active counter.
You can access these performance counters using the System.Diagnostics namespace.
This code worked for me:
PerformanceCounter pc = new PerformanceCounter("ASP.NET Applications",
"Sessions Active", "__Total__", "MYSERVERHOSTNAME.domain");
while (true)
{
Console.WriteLine(pc.NextValue());
System.Threading.Thread.Sleep(1000);
}
I had this problem so take a look here if the counter seems too high: http://support.microsoft.com/kb/969722
As a general principle, you have to define what you mean by the number of users online.
For example, Sessions usually last for a predefined duration, such as 30 minutes. Depending on how long you expect users to be on your site, the duration of a session could be largely attributed to idle time when the user is not on your site.
In general you want people that have been online in the last n minutes. Sessions give you this statistic for one period of time (the configured session expiry), but there are many other time measures that would potentially be more relevant.
One way to accomplish this is to simply have the IIS logs shove their data in a table in your database instead of the local file system. This is pretty easy to configure at the web server level.
Then you could easily graph that and show usage throughout the day, current, weekly, etc.
Of course, if you have a highly trafficked site, then this would result in a tremendous amount of data collected.
For EPiServer websites you may want to have a look at Live Monitor: http://www.episerver.com/add-on-store/episerver-live-monitor/
In ASP.NET MVC, what is a good way (the preferred way??) to time how long a user has been on a specific page? For example, I want the user to select something and then only allow the user to do something for 30 seconds. Good links or a reference to a page of a book would be much appreciated.
Thanks in advance!
You can keep track of when a user went somewhere and how long they have been there (or had the page open while balancing their check book...you get the idea). The problem is that you need some form of client controller to let them see XYZ for 30 seconds...and then redirect them to the next page that they can see. So if you wan the user to see a resource for X amount of time you need to employ a javascript client side timer to take them away from the resource when their time is expired. This can be done with the time statically coded to the client (which could be changed by the client) or it can be done by making an AJAX request to the server to see if the time has expired. Or it could be done with an embeded flash player. The key here is that your server side doesn't have as much power over the client side as what you are requiring. Most testing sites deploy some form of this client side javascript to keep track of what the user is doing, when, and for how long!
One pretty easy way is to store the last time the user was on the page in a database - the table could have, for example, the fields UserID, Page, and TimeStamp. Whenever the user tries to do whatever you only want to allow for 30 secs, you check against the database if the time has passed or not. (For such short periods of time as 30 seconds, a database might be a little too slow, though... Depends on your requirement of precision, I guess...).
You could use JavaScript's setTimeout() function:
var timeOut = function() {
alert('Time is up!');
}
setTimeout (timeOut, 30000);
Or you could use a <meta> tag:
<meta http-equiv="refresh" content="30;url=http://www.example.com/time-is-up.html">