Receive notification in ASP.net if table from SQL was Updated/Changed - c#

Is it possible to get notification in my ASP.net Website from database if a table was been modified?
Example: if there is new message that come to my account. It will notify me on my website. I've tried to use ajax on this kind of feature but I want a better solution on this. AJAX is keep on requesting/communicating on the server even there is not new update on my table that why I find it not that good.
Please Help me on this problem.
What technology I should use? or please give me some related article.
Thanks!

No, it is not possible to get notification to your ASP.NET Website without an ajax request which keeps on communicating to a server in a given time interval. You can use SQL triggers to get information that your table has been updated or row has been added/deleted but to get that information too you'll need to make a request to your database server. I haven't came across any architecture in which database server automatically communicates to your web application/website until and unless a request is made by web application/website.

Related

Add request function to CRUD model that sends an email

I have no background in programing, but my job wants me to learn. I have built a simple .asp mvc project that is a database of movies and such. I need a request form for a movie that can be filled out and if that movie is added then the client would be sent an email. Can anyone give me an idea on how I could accomplish this task. Thank you for anyone who has time to even point me in the right direction.
It's pretty straightforward to do … you need to:
get data from form (seems you already have the form)
check with db if movie added (use Entity Framework, or some other ORM)
send email based on result (You can use services for this -- sendgrid, I think twilio does it, or you can just use an smtp client if you already have a server address) …
Search/learn for each of these individually to get your project complete.

Masking 1000 ajax post request with better performance

We have an application that is installed on some 600 odd servers. This application exposes a web api which gets me version information of the application.
My requirement is to display the version of application on each of the server. I have achieved this in asp.net application by:
Writing a web method in aspx.cs page with server name as parameter. This method will build web api URL, invoke web api, get response, build a object and return as json string.
I have written an jquery ajax post request for each server name to the above method. On success, built a html table row and append it to table. so that as and when we get response it is shown to user.
This works absolutely fine for say 30-40 servers. But when it increases, it takes lot of time to process all requests (30 - 40 mins). And with multiple users using this asp.net app, we start getting error.
Is there a any other method to achieve this faster and for multiple users without errors?
How often is this information changed? If this data is rarely updated, I suggest the following.
Make every of servers to save this information into a shared database table when the server starts. If the application version can be changed while the server is operating, update a corresponding record in a database.
When your service gets information about the application version, get it once from the database table instead of requesting it directly from every server.

Servicestack server sent events - email application

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

Is it possible to use asp.net httprequests to send data to PHPmyadmin?

I developed a website over php that sends and retrieve data from phpmyadmin. Through this way, I want to be able to send data from my smart phone (android) to phpmyadmin and I was told that this can be done through HTTPrequests; however, I was also told that it is possible on asp.net only.
My application (as a test) is built to just register a user and let him/her get logged in. I am just stuck to the point where I am not sure how to send data from the phone to phpmyadmin..
Is it possible to just use asp.net to retrieve and send data
using httprequests and then post them on phpmyadmin? Or do I just redo
my entire website over asp.net?
I have little knowledge about asp.net, but I would just like to hear an opinion from the professionals on this website!

Refresh asp.net page from a code-behind file

I have an ASP.NET website and a seperate C# application. The application writes data to a file, the website populates the treeview with the data in the file. I populate the treeview in the page Load event.
The website checks if the file has changed. This happens from a code behind file. If the file did change, the website needs to be refreshed. I cannot use Response.Redirect because I get a
Response is not available in this context
I tried System.Web.HttpContext.Current.Response.Redirect, but this gives me a NullReference.
How can I refresh the page from a code behind file, so that it loads the right data in the treeview? Other suggestions that work but use something else than refreshing the page are welcome. Thanks in advance!
Edit: The actual problem is dynamically updating the treeview (new data = updated treeview). I have tried to do something with data from a MySql database but failed. The idea is the same, except the data isn't coming from a file but from a database. I added this because I thought this info might help users understand my problem.
you can't send data to the client from an initiative of the server.
You will have to poll (jQuery/ajax) if new data is available, then refresh from the client side.
this involves basically :
on the server
a web service, webmethod page method, custom handler, etc. that can tell if new data is available
on the client
a timer that query the server if data is refreshed, and, in this case, that refresh the page, or reconstruct the DOM if using some JS templating
[Edit] a bit of background :
Actually, System.Web.HttpContext.Current.Response is null because of the asynchronous model of the Http protocol. The browser emits a request "http://srv/resource", the server intercept it on the port 80 (by default), parse the request, build a response (mostlya bunch of html content) and send the response the browser. Then the connection is closed. This choice allows a great scalability, as it does not requires to keeps thousands of connections alive with nearly no data passing on it.
The impact of this, is that the web server have to knowledge of the client, other than what is send in the request. The server receive text, and send text in return.
Microsoft has created the ASP.Net framework to reproduce the RAD feeling of desktop applications. You think with controls and events, not in producing html flow like ASP or PHP. They succeeded in the sense, that, building web apps are quite similar to desktop development.
The quite is actually what is causing you some confusion. Even if the asp.net framework encapsulate most of the plumbing (viewstate is the key) to simulate this behavior, asp.net will, at least, still be a parser for request text that produces a html text to send to the client, in one shot.
So you have to cheat. You can, as I suggested, automate the browser (using javascript) to wrap this asynchronous work into a "dynamic" application.
You can't successfully use a FileSystemWatcher from within a webpage.
The instance of the page lives just long enough to handle a single request. And after that request has been served, you can't issue a redirect. The browser will not be listening anymore.
You need to do polling from your webpage, using the date you last read that file. If the Last Modified date of that file has changed from what you remember, you will need to refresh your page.

Categories