I need to send "instant" messages (like forum PMs) between users with my asp.net application. As many others I use a webhotel to host my site. I have searched around for awhile and I can't find any solutions that would be a good fit with my system. I was thinking about writing a javascript that would call for each 30 seconds or so a .ashx handler to check the users message status (return true or false) if the correct credentials are supplied. However I dont know if this is a good solution, because of all the calls to the handler it might get picked up as spam or it might generate really bad performance? The thing is, I want to avoid the need to refresh the page just to see your latest messages.
Take a look at the C# SignalR library, it allows you send grouped or broadcast messages to clients using longpolling or websockets with minimal bandwidth and simple code
http://signalr.net/
You can use an updatepanel for this. Put a textbox in an updatepanel in your page. When a user sends a message just append it to that textbox.You can put a refresh timer to refresh the contents in every second .
Related
I have an Azure function that runs a few times a day. I'd like to email myself a daily list of log messages, and wondered if I could use another Azure function for that?
Is it possible to read an Azure function logs from within an Azure function? Or is there another way to achieve the above?
Or is there another way to achieve the above?
Yes, you can use Azure Logic apps to get the logs of Function app recurrently.
I have created a logic app in Consumption plan, then created a workflow with Recurrence Trigger like below:
Then in next step I have chosen the Azure Applications insights like below:
Then I have opted send an email action and then I got the logs to my email :
Then in email I received logs:
I would propose two possible solutions in the realm of Azure.
In both cases I would suggest to include application insights.
It is a general recommendation by Microsoft.
Then goes what Peter Bons called "use case".
If it is enough for you get the critical information about recurring issues with N minutes of frequency, then you could make us of alerts. Last time I checked one needed to pay extra for each email, please double-check that.
If for some reason you want to have more control over what logs you want to send and fetch, you can fetch data directly from application insights through the REST API. To complete the idea you could use bindings that allow send emails (see here for practical points). I would say that there variations on how you can achieve fetching data, although the feature will be deprecated in two years.
Can anyone guide me, where to find servicestack server sent event sample code.
First I explain my issue. I have created a restful service(using servicestack framework) to pull down list of emails for inbox folder using afterlogic mailbee object(external product). Now, each time if I do a pull, it takes more time to load list of emails because I am pulling down message body too.
Now I want to send down list of message headers first in the service, and then want the message body to load, because it take more time to pull down from imap object. I see server sent event is the only option here. If someone has a better solution for this, please suggest.
Now, if I have to use servicestack server sent events, I am unable to get any sample code, which I can look upon to implement in my case.
Please ask, if there is more clarification needed in my question.
Thanks for your time.
There is a sample for your requirement.
It is called Chat (it uses SSE).
Otherwise another project called EmailContacts can help you to develop the email app.
Server Events is to enable server/push real-time communication, if you want to optimize page loads you should separate your calls into 2 Services:
Fetch absolute minimum to render page
Fetch full details on demand
i want to make something like a friend status if he is online or offline.
c# code behind, javascript , html5
There is a similar question but it uses .php and i dont know anything about php.
Anyway I was thinking that for the online, you can track when the user has actually logged on.(turn a field in the DB for online to true)
But how do you send that info to the person who needs to know if the other user logged in? can the codebehind or the js have like a receiving function/method that is called when he gets online?(like an observer pattern?)
also then when it updates we dont want a whole page refresh but the least possible #flickering for the page. post-back?
Finally to track if the user is offline it could be like a http response to check for a responce from the online user if he is still online. But how? :P
If we finally get that its offline can we use the same receiving function/method that we informed the other person that he was online?
Any help would be much appriciated. Hope this could become a reference for similar threads.
But how do you send that info to the person who needs to know if the other user logged in?
You can't send the information to the user. He must get the information himself. What I mean is that http is a "pull protocol", which means that you can't push information to the client, you just give him what he requests.
Now, what you want is the client to request the information without noticing the fact that his browser is sending requests. The best way to do this is to use Ajax in javascript to send a request to a web service. This way, you can get information from your server without doing any postbacks. Then, to give an impression of live information, you'll want to set your ajax call in a setTimeout to get the information any given time interval (30 seconds, 1 minute, your choice).
To simplify - a lot - your ajax calls, have a look at Jquery Ajax.
If you don't know any of this, don't give up, it may look more complicated than it actually is.
Finally to track if the user is offline
What I suggest is that you keep track of every request from that user, and after a certain time without any request, you declare this user as logged out.
Hope this helps!
In a Website environment how do you make an ajax post to Handler.ashx secure and how do you stop people calling that handler.ashx directly and putting rubbish in and possibly breaking things server side?
With firefox and firebug you can pretty much hack the post quickly and easily.
I was thinking of these ideas.
In the handler check if you are logged in.
List item on the load of the site create a unique ID is saved as a cookie and
when the handler is called then that ID must exist in the Ajax and
the handler
List item the ajax call must come from a certain page
Do you have any other ideas?
Thanks
Short answer
Use authentication (Windows, Forms, etc) and validate your input.
Slightly longer answer
If your site is configured with an authentication provider, your handler will follow the same rules.
You should always validate any user input or web service input. Don't assume that your client is giving you pristine input. As you have mentioned, anyone with basic web development skills can spoof a POST. Keep that in mind when validating.
I am building a web application in asp.net MVC and am thinking how I can get certain conditional tests to happen regularly.
Currently I am planning on having a page such as /utility/runJobs that will have a function in it that will test the whole site for dates meeting certain conditions etc..
I would then trigger this page from a service or other trigger service.
I would probably run this every min incase new notifications had to be sent out, or a Log item had to be written, or a status updated.
Can anyone suggest a better way of doing this.
EDIT___________
Imagine how the notification emails for ebay are sent?
I guess that the badges on stack over flow are tested when a user comes to the site, and only for that user.
If you are planning to write a Service to trigger your Jobs then I would suggest that you execute your jobs in your Service.
With MVC you have hopefully already separated you logic from you Views so it should be easy to implement the service.
First big protip: what you are looking to do shouldn't require a single web page. Or, what you really need to think about here is services, command line apps and queuing, not having a page that gets hit once a minute.