Monthly Archives: July 2012

C# MSSQL

Writing form data to SQL DB with C#

In having to convert my current VB projects into C#, I ran into an issue trying to write to a DB from a form.  This blog opened my eyes to how this is accomplished and here is the code I used to get the unsubscribe feature to work.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace Taleo_UnsubscribeJPN
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DateTime tstamp = DateTime.Now;
String email = Request.QueryString["email"];
String atsid = Request.QueryString["atsid"];
lblEmail.Text = email;

}

protected void btnRemove_Click(object sender, EventArgs e)
{
String strBrowserInfo = (Server.HtmlEncode(Request.UserAgent));
String strIPAddress = (Server.HtmlEncode(Request.UserHostAddress));
String atsid = Request.QueryString["atsid"];
string connection_string = "Data Source=DB_Server;Initial Catalog=TaleoData;Persist Security Info=True;User ID=tdowner;Password=password";
string query = "insert into OptOutEmail (email, tstamp, processed, atsid, remote_addr, http_user_agent) values ('" + lblEmail.Text + "', '" + DateTime.Now + "', " + 0 + ", '" + atsid + "', '" + strIPAddress + "', '" + strBrowserInfo + "')";
SqlConnection connection1 = new SqlConnection(connection_string);

SqlCommand insertCommand = new SqlCommand(query, connection1);

connection1.Open();

insertCommand.ExecuteNonQuery();

connection1.Close();

Server.Transfer("Confirmation.aspx?email=" + lblEmail.Text);

}
}
}

IIS

Binding https Protocol to 2 Sites with Host Headers

I almost didn’t know what the hell to title this post because it’s almost too obscure to understand.  Here’s the skinny:

I’m having to move our DNN site from a server that is on life support (win2k3/IIS6/32bit) to a brand spanking new VM (w2k8/IIS7/64bit).  Sounds like fun doesn’t it?  Well the main problem is that the default web site is DNN but we also have to host an unsubscribe form so if you don’t want job notices you just click remove and we stop sending notices.  Should be nice and easy to set up host headers to catch this.  And if works fine and well if you just want to do it on port 80.  But god forbid you want to use host headers for SSL.  You have to use the appcmd.exe from the command line to do this.  Now I have no idea how it works but here is what did the trick for me and binding the unsubscribe site to SSL with host headers:

appcmd set site /site.name:”unsubscribe” /+bindings.[protocol=’https’,bindingInformation=’*:443:unsubscribe.pdstech.com’]

And just a note I found on technet, even if you are running a 64bit server don’t use the exe from the syswow64 directory, so much for consistancy MSFT:)