0

我已经根据数据库服务器数据插入在 asp.net 页面上显示通知或警报,所以我想知道是否可以通过推送模型来执行此任务?

4

1 回答 1

1

您可以使用 SignalR 将通知从您的 Web 服务器发送到您的客户端:http ://signalr.net/ 。

要将通知从 SQL Server 发送到您的 Web 服务器,您可以使用SqlDependencySqlCacheDependency类。

根据指南, http: //msdn.microsoft.com/en-US/library/9dz445ks (v=vs.110).aspx ,

SqlDependency.Start(myConnectionString);

using (SqlConnection connection = new SqlConnection(myConnectionString))
{
    using (SqlCommand command = new SqlCommand("SELECT ... FROM MyTable", connection))
    {
        SqlCacheDependency dependency = new SqlCacheDependency(command);
        // Refresh the cache after the number of minutes
        // listed below if a change does not occur.
        // This value could be stored in a configuration file.
        int numberOfMinutes = 3;
        DateTime expires = DateTime.Now.AddMinutes(numberOfMinutes);

        Response.Cache.SetExpires(expires);
        Response.Cache.SetCacheability(HttpCacheability.Public);
        Response.Cache.SetValidUntilExpires(true);

        Response.AddCacheDependency(dependency);

        connection.Open();
    }
}
于 2013-08-10T12:31:46.503 回答