Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following code has been developed using C# language.

Code Block
languagecsharp
linenumberstrue
<script runat="server" language="C#"> 

...


void Subscribe() 

...


...


string retCode = "1"; // if retCode = 1 returned value is an error code, if retCode = 0 returned value is the error text 

...



string ret_val = SubscribeUser(retCode); 

...



// Once the value has been returned it is possible to decide what to do/view

...



// ******************************************************** 

...


// If retCode = 1 returned values are the following: 

...


// 0 : Operation completed 

...


// 1 : Generic error

...


// 2 : Invalid email address

...


// 3 : User already subscribed

...


// ******************************************************** 

...



switch(ret_val) 

...


...


case "0": 

...


// Display a message saying the user was subscribed successfully 

...


break; 

...


case "1": 

...


// Display a message saying the service is not accessible at the moment

...


break; 

...


case "2": 

...


// Display a message saying the email address in an invalid address

...


break; 

...


case "3": 

...


// Display a message saying that the user is already subscribed 

...


break; 

...


default: 

...


// Display a message saying the service is temporarily unavailable

...


break; 

...


...




//************************************************************************** 

...


// If retCode = 0 error text is returned

...


//************************************************************************** 

...


// For example, the value ret_val can be associated to a Label object

...


...



// This function calls the user's registration page and returns an output value 

...


string SubscribeUser(string retCode) 

...


...


string strEmail = Request.Params["email"]; // user's email address

...


string intList = Request.Params["list"]; // list ID 

...


string intGroup = Request.Params["group"]; // group to which to subscribe the user (optional) 

...


string blnConfirm = "1"; //Confirmation request

...


string csvFldNames = "Field1;Field2;Field3;Field4"; //Field names are taken from the Codes Table

...


string csvFldValues = "Name;Surname;Company;M"; //Values are assigned to the corresponding fields in the same order as csvFldNames 

...


string result = ""; // returned value

...



string url = "http://newsletter.nomedominio.tld/frontend/xmlSubscribe.aspx"; 

...


url += "?list=" + intList + "&group=" + intGroup + "&email=" + strEmail + "&confirm=" + blnConfirm.ToString() + "&csvFldNames=" + csvFldNames + "&csvFldValues=" + csvFldValues + "&retCode=" + retCode; 

...



System.Net.HttpWebRequest wreq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); 

...


wreq.Method = "GET"; 

...


wreq.Timeout = 10000; 

...



System.Net.HttpWebResponse wr = (System.Net.HttpWebResponse)wreq.GetResponse(); 

...



// If the page answers correctly the return value is obtained 

...


if (wr.StatusCode == System.Net.HttpStatusCode.OK) 

...


...


System.IO.Stream s = wr.GetResponseStream(); 

...


System.Text.Encoding enc = System.Text.Encoding.GetEncoding("utf-8"); 

...


System.IO.StreamReader readStream = new System.IO.StreamReader( s, enc ); 

...



// vreturn value

...


result = readStream.ReadToEnd(); 

...


...



return result; 

...


...


</script>

 

 

More integration possibilities for a subscription form

...