将数据绑定到.ashx文件



我正在构建SMS Getaway,并且正在使用SMS Enabler。这是我的例子,一个人通过短信发送一个代码。这个代码在SQL Server数据库中循环,并检查这个列中是否存在这个代码,比如在数据库测试表TAGLE1的CODES列中。如果此人员存在于此列中的代码SMS Enabler回复他是获胜者的代码,否则该代码不存在,则回复"重试"。我只能通过.ashx文件而不是.aspx文件来完成此操作这是我的代码:

public class sms : IHttpHandler {
 // This method is called each time a new SMS message arrives
 public void ProcessRequest(HttpContext context) {
   // form variables (contain all sms message information)
   var sms = context.Request.Form;
   // sender's number
   string senderNumber = sms["sender"];
   // sms message text
   string messageText = sms["text"];
   // SMS center timestamp in UTC. You can consider this
   // as the date and time when the sender sent the message.
   DateTime sentTime = DateTime.ParseExact(sms["scts"],
         "yyyy'-'MM'-'dd HH':'mm':'ss", null);
   // SMS center number (not supported when using SMS Enabler 
   // with a Nokia phone)
   string smscNumber = sms["smsc"];
   // Tag value. You can define this in SMS Enabler's settings, 
   // and use it to pass additional information.
   string tag = sms["tag"];
   /* TODO: 
      WRITE YOUR CODE FOR PROCESSING INCOMING SMS MESSAGES HERE */
   // Sending a reply SMS. If you don't want to send a reply, 
   // just comment all the next lines out.
   context.Response.ContentType = "text/plain";
   // Add an X-SMS-To header to set the recipients of the reply. 
   // If not set, the reply is sent to the sender of the 
   // original SMS message.
   // context.Response.AddHeader("X-SMS-To", 
   //      "+97771234567 +15550987654");
   // Write the text of the reply SMS message 
   // to the HTTP response output stream.
   context.Response.Write("Reply SMS message");
 }
 public bool IsReusable {
   get {
      return false;
   }
 }
}

我唯一想要的是如何将数据绑定到.ashx文件上,循环通过它,检查它的正确或错误,然后回复。

没关系。我找到了的解决方案

SqlConnection con1 = new SqlConnection();
        con1.ConnectionString = ConfigurationManager.ConnectionStrings["NDERMJConnectionString"].ToString();
        string sql1 = "select Count(*) from tablename where name= @name";
        SqlCommand cmd1 = new SqlCommand(sql1, con1);
        cmd1.Parameters.AddWithValue("@name", sms["text"].ToString());
        con1.Open();
        int result = (int)cmd1.ExecuteScalar();
        if (result > 0)
        {
            context.Response.Write("You are the winner");
        }
        else
        {
            context.Response.Write("I'm sorry. Try Again.");
        }

最新更新