可以使用c#在asp.net中使用push模型

时间:2013-08-10 12:21:36

标签: asp.net

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

1 个答案:

答案 0 :(得分:1)

您可以使用SignalR从您的网络服务器向您的客户发送通知:http://signalr.net/

要将通知从SQL Server发送到您的网络服务器,您可以使用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();
    }
}