Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

IS it possible? calling or accessing classic asp from .net(C#)

Hi,

I have a web page that will insert a brokers data as well as an lO_Information. this page have two text boxes that will enterd brokers email as well as lo's email. I want to be able  send an email to this email addresses(there are 2 classic asp generated pages)from the classic asp. how can i do that. we don't (atleast my boss)want to change the asp pages to .net so if it is  possibel please tell me how here is the code that will insert into the tables that I mentioned above.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for NewBroker
/// </summary>
public class NewBroker
{
    public string BrokersID;
   

      public NewBroker()
      {
            //
            // TODO: Add constructor logic here
            //
      }
    private string getConnectionString()
    {  
        //get the connection string from web.config
        string sqlconnection = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
        return sqlconnection;
    }
 
   
    public string checkDuplicate(string company, string address, string city, string state, string zip,string phonePre, string phone,string faxPre, string fax, string email)
    {
         SqlConnection sqlConnectionString = new SqlConnection();
            sqlConnectionString.ConnectionString = getConnectionString();
        try
        {
            //checking for dups
            String strCommand = " Select B.DBA from DMD_Data.dbo.brokers B where B.dba like '" + (company) + "%' and B.address like '" + (address) + "%'and B.state ='" + (state) + "' order by DBA ";
            SqlDataAdapter da = new SqlDataAdapter(strCommand, sqlConnectionString);
            DataSet ds = new DataSet();
            da.Fill(ds, "Brokers");
            int countDup = ds.Tables["Brokers"].Rows.Count;
            if (countDup > 0)
            {
                return null;
            }

            else
            {
                // instancsiate the BrokerManager Class so that an insert to the brokers tabel on dmd_data can be performed
                BrokerManager bm = new BrokerManager();
                bm.Insert(company, address, city, state, zip, phonePre, phone, faxPre, fax, email);
                string ComBroker = "select B.brokers_id from DMD_Data.dbo.Brokers B where B.dba = '" + (company) + "'and B.address='" + (address) + "'and B.state='" + (state) + "' and B.cur_status='PENDING'";
                SqlCommand cmd = new SqlCommand(ComBroker, sqlConnectionString);
                sqlConnectionString.Open();
                // this brokerID will be inserted to the intranet.lo_infromation tabel
                string brokerID = (string)cmd.ExecuteScalar();
                return brokerID;
            }
        }
        catch (Exception e)
        {
            throw new Exception("Connection Can not be made", e);
        }
        finally
        {
            if (sqlConnectionString != null)
                //sqlConnectionString.Dispose();
            sqlConnectionString.Close();
               
        }
   
   
    }
    public string insertState(string company, string address, string state)
    {
        SqlConnection sqlConnectionString = new SqlConnection();
        sqlConnectionString.ConnectionString = getConnectionString();
        try
        {
            string stateCommand = "select B.state from DMD_Data.dbo.Brokers B where B.dba = '" + (company) + "'and B.address='" + (address) + "'and B.state='" + (state) + "' and B.cur_status='PENDING'";
            SqlCommand cmd = new SqlCommand(stateCommand, sqlConnectionString);
            sqlConnectionString.Open();
            string appState = (string)cmd.ExecuteScalar();
            return appState;
        }
        catch (Exception e)
        {
            throw new Exception("Connection Can not be made to the database",e);
        }
        finally
        {
            if (sqlConnectionString != null)
            {
                sqlConnectionString.Close();
            }
        }
    }

    public int LoInsert(string BrokersID, string fName, string lName, string loPhonePre, string loPhone, string loFaxPre, string loFax, string LoEmail, string approvedState)
    {

       
        SqlConnection sqlConnectionString = new SqlConnection();
        sqlConnectionString.ConnectionString = getConnectionString();
        try
        {
            string insCommand = string.Format("INSERT INTO INTRANET.dbo.LO_INFORMATION (broker_id,first_name, last_name,phone_pre,phone, fax_pre,fax, email_address, approved_States)" +
                                "VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')SELECT SCOPE_IDENTITY()", BrokersID, fName, lName, loPhonePre, loPhone, loFaxPre, loFax, LoEmail, approvedState);
            SqlCommand strCommand = new SqlCommand(insCommand, sqlConnectionString);
            sqlConnectionString.Open();

            int Lo_Id = Convert.ToInt32(strCommand.ExecuteScalar());

            string zeros = null;
            string autoLogin = null;
            string autoID = Lo_Id.ToString();
            if (autoID.Length == 1)
            {
                zeros = "0000";
            }
            else if (autoID.Length == 2)
            {
                zeros = "000";
            }
            else if (autoID.Length == 3)
            {

                zeros = "00";
            }
            else if (autoID.Length == 4)
            {
                zeros = "0";
            }
            else if (autoID.Length == 5)
            {
                zeros = "";

            }
            autoLogin = "L1" + zeros + autoID;
            string autoCommand = "Update INTRANET.dbo.LO_INFORMATION SET lo_login='" + (autoLogin) + "' where auto_id = " + Lo_Id + " ";
            SqlCommand cmd = new SqlCommand(autoCommand, sqlConnectionString);
            cmd.ExecuteScalar();
            return Lo_Id;

        }
        catch (Exception e)
        {
            throw new Exception("Connection Can not be made to the database",e);
        }
        finally
        {
            if (sqlConnectionString != null)
            {
                sqlConnectionString.Close();
            }
        }
    }
   
 
   

}
0
jemigossaye
Asked:
jemigossaye
  • 4
  • 3
1 Solution
 
pauljk1619Commented:
To do it in classic ASP....

Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing


In your C#....

using System.Web.Mail;

MailMessage objMessage;
objMessage = new MailMessage();
SmtpMail.SmtpServer = "localhost";
objMessage.To = Email;
objMessage.Body = Message;
objMessage.Subject = Subject;
objMessage.From = "GHTDispatch@ghtow.com";
SmtpMail.Send(objMessage);
0
 
pauljk1619Commented:
You will have to have an SMTP server that you can relay off of with the proper permissions to do so.
0
 
jemigossayeAuthor Commented:
I already have the classic asp (actually 2 of them) mail sender.  How can i incoporate that in my C#
and just send the emails to the appropriate email address that the users have inserted
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jemigossayeAuthor Commented:
PS. we don't want to convert the classic asp to C#
0
 
pauljk1619Commented:
Are you looking to Post the data to your ASP pages?
0
 
pauljk1619Commented:
You could try posting the data to your asp page.  Here is a sample.  I have no idea how your ASP pages are written, so it's a rough sample.  :)

      ASCIIEncoding encoding=new ASCIIEncoding();
      string postData="userid="+LName;
      postData += ("&Email="+LoEmail);
      byte[]  data = encoding.GetBytes(postData);

      // Prepare web request...
      HttpWebRequest myRequest =
        (HttpWebRequest)WebRequest.Create("http://localhost/MyEmailPage/SendEmail.asp");
      myRequest.Method = "POST";
      myRequest.ContentType="application/x-www-form-urlencoded";
      myRequest.ContentLength = data.Length;
      Stream newStream=myRequest.GetRequestStream();
      // Send the data.
      newStream.Write(data,0,data.Length);
      newStream.Close();
0
 
jemigossayeAuthor Commented:
yes, taking the id to make some kind of conditional statment and take the email address to the asp and then using the format that is in the ASP send the email to the appropriate email address
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now