SignalR 2.0 with database update asp.net - 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!

Related

Architect website/mobile notifications generated by users activities

I am working on a mobile application, this application has some features like users can follow each others, adding comments or reviews, like something .. etc.
So the requirement is we have notifications icon in the app, when the user click on it a list of notification will show up, taken in consider those notifications should be real time.
Many things comes to my mind will reviewing this feature, like using firebase to send the notification, or I can develop internal notification service for this purpose.
The question is what do you suggest guys, do you think using firebase is a good idea for such case? or there is something else you recommend for such case
Thank you in advance.
You can try signalR more manageable than firebase but you need to know programing to manage signalR

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

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...

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