How to Push some data from Database to asp.net webform? - asp.net

I want to push some thing (like Notification) to user's page, i tried a function that search database and then DB had new notification, it showed the Notification to us, but it was a bad way, someone know how i can do it better?

You can use Comet or SignalR. This is a LINK to explain how use it

You need to implement Client side side based code, so use ajax and java script to that...

Related

SignalR 2.0 with database update asp.net

I needed to do some notification concept for my asp.net project like facebook notifications. if a user added something in database. the notification icon will be +1 and when you click the icon, you'll see who added what to database like fb. so i needed to run SignalR function if database update is OK in codebehind. I'm new in SignalR and trying to figure it out. i'm not working with MVC btw. trying some tutorials now. so keep it easy please :)
The way I see this, I would notify my clients right after the database operations. So it would look something like this:
db.Save(objectToSave);
var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.All.notifyChange();
In this way, you are able to call clients from outside your hub, so you can have this sort of calls to your clients right after you update the database.
You can also have a look at this tutorial , also this one explains notifications..
If you are familiar with working with databases, keep in mind the approach: just call your clients right after saving in the database.
Hope this helps. Best of luck!

which one is better to use SignalR or requestanimationframe?

I have been developing an application which contains instant notifications but I am a little confused about what is the best to use to get instant notifications, is it better to use the client side requestanimationframe method or to use signalR?.
so please could anyone explain which one should I use and why.
This is one of the best use cases for SignalR. Create a Hub on which you connect your client and send notifications from there.
You can have a look here - http://www.codeproject.com/Tips/672433/Real-time-Notifications-with-SignalR
Hope this helps! Best of luck!

asp.net + private message system notification

I am trying to build a private message inbox system in my asp.net app, using SQL Server to store the messages between users but one thing I am not sure how to achieve is this, for e.g facebook immediately notifies a user when he/she recieves a new message or notification through the action of another user as a red icon on its top navigation bar. I have read through some of the tutorials and guides and most of them requires some sort of polling to the database every few seconds. Can anyone shed some light on what is a good way to go about this?
Thanks.
I have used SignalR to do something similar to this in the past. It can be installed via NuGet by Install-Package SignalR
Scott Hanselman has a great write up: http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx
Also, jabbr.net is a fully functional example of what, I think, is pretty close to what you want to do.

How can I pass FormsAuthentication.SetAuthCookie from Data Access Layer Class to WebService to Javascript?

I am using DotNetOpenAuth in my ASP.Net Website. I have modified it to work with Facebook Connect as well, using the same methods and database structures. Now I have come across a problem.
I have added a Facebook Connect button to a login page. From that HTML button, I have to somehow pull information from the Facebook Connect connection and pass it into a method to authenticate the user. The way I am currently doing this is by:
Calling a Javascript Function on the onlogin function of the FBML/HTML Facebook Connect button.
The javascript function calls a Web service to login, which it does correctly.
The web service calls my data access layer to login.
And here is the problem: FormsAuthentication.SetAuthCookie is set at the data access layer. The Cookie is beyond the scope of the user's page and therefore is not set in the browser.
This means that the user is authenticated, but the user's browser is never notified.
So, I need to figure out if this is a bad way of doing what I need or if there is a better way to accomplish what I need. I am just not sure and have been trying to find answers for hours. Any help you have would be great.
Yes, it sounds like you are having a design crisis brought on by trying to do too much at one time/in one place.
If you break this operation up in to two calls from the client you will find your options opening up quite a bit. It might take some more work but ultimately the code will be less complex. <-- a good thing.
And in my opinion, the first clue pointing to a crisis of design would be when I said to myself "Self, having an authentication method buried two calls deep in my DAL is not working the way I would like...." lol.... I am joking and serious same time.
Good luck.

Communication between pages

I want to enable an user to be able to communicate with other users through a site. I know that ASP.net is stateless, but what can I use for this synced communication? Java servlets?
I don't think you need to set up Java just to use a servlet for this. I would use AJAX and the database. I don't know ASP.NET but I PHP is similar in this case, being also basically "stateless". If you want to display some kind of asynchronous communication between two different users, say, from two different sessions, without a lot of refreshing (like chat), you can have the AJAX page constantly poll the database for new messages, and display them when they come in. You can also use AJAX to insert the new messages, giving the user read/write access to this messages data structure. Since the "other" user is doing the same thing, user A should see new messages pop up when user B types them in.
Is that what you mean?
You probably don't want to use sessions for things like chat messages but you probably could use some type of implementation of queueing using MSMQ.
The approach to chat could be done in many different ways, this is just a suggesting off the top of my head.
Could do a messaging solution in Java Servlets using the application context. Objects stored as attributes in the application context are visible from anywhere in your webapp.
Update: Chat like functionality... I guess that would be AJAX polling your message structure stored in the app context unless you want to use something like applets.
Don't know if it's any good, but there's a chat servlet here that might be useful to use or learn from if you decide to go the Java route...
ASP.NET is "stateless" but it maintains state using Sessions. You can use them by default just using the Session[] keyword.
Look at ASP.NET Session State for some details from Microsoft.

Resources