03 March, 2014

How to send email in ASP.net

Please click the link and view the post new domain : http://mahedee.net instead of this. I am not updating blog here. I am writing and updating blog in http://mahedee.net

You have to configure SMTP server before sending email from your server. Hope you already know how to configure smtp server. Here is the simple code segment for sending email against a button click.

 protected void btnSendMail_Click(object sender, EventArgs e)
    {
      
        SmtpClient smtpClient = new SmtpClient(); 
        MailAddress fromAddress = new MailAddress("mahedee_hasan@leads-bd.com"); //Sender email address
        MailMessage _mail = new MailMessage();

       _mail.Attachments.Add(new Attachment(@"E:\Temp\attachment.pdf")); //Add dirctory of attachment
         
        
        //bool IsSuccess = false;
        try
        {
            _mail.From = fromAddress; 
            _mail.To.Add("mahedee.hasan@gmail.com"); //Receiver email address
            _mail.CC.Add("mahedee.hasan@yahoo.com"); //Email address for cc
            _mail.Bcc.Add("mahedee.hasan@hotmail.com"); //Email address for bcc


            _mail.Subject = "Test Message"; //Email subject
            _mail.Body = "Dear concern, This is the test message from Mahedee"; //Email body
            _mail.IsBodyHtml = true; //Email body is in html format

            smtpClient.Host = "182.268.30.50"; //Name or IP address of the host used for SMTP transaction
            smtpClient.EnableSsl = false;
            //smtpClient.Port = 25; //25 is default port for smtp. You have to change port no if it is not used defualt port 
            smtpClient.Send(_mail);   //Send mail
            //IsSuccess = true;
        }
        catch (Exception ex)
        {
            //IsSuccess = false;
        }
        finally
        {
            //
        }

    }

02 February, 2014

How to register .NET framework in IIS

Please click the link and view the post new domain : http://mahedee.net instead of this. I am not updating blog here. I am writing and updating blog in http://mahedee.net

If you install IIS after installing framework, you have to register framework in IIS. Otherwise you will get following message after hosting asp.net application in IIS.

ASP.NET 4.5 has not been registered on the Web server. You need to manually configure your Web server for ASP.NET 4.5 in order for your site to run correctly.

You may get error of different version instead of 4.5 according to your configuration. So to register framework in IIS, run the following command in command window.
  • Register framework to IIS without changing existing web applications to use this version of ASP.net
C:\windows\Microsoft.NET\Framework\v4.0.30319->aspnet_regiis –ir
  • Or Installing framework to IIS
C:\windows\Microsoft.NET\Framework\v4.0.30319->aspnet_regiis –i

This installed ASP.NET version v4.0.30319 without updating all script maps. After installing Rational

System Architect XT, the following command was run:
C:\windows\Microsoft.NET\Framework\v4.0.30319->aspnet_regiis -s W3SVC/1/ROOT/SAXT

This installed ASP.NET version v4.0.30319 at the specified application root and its subfolders. All existing script maps in the specified path and below were updated.

For the Rational System Architect XT Web Service add-on product, the Registration tool was run with the following command:
C:\windows\Microsoft.NET\Framework\v4.0.30319->aspnet_regiis -sW3SVC/1/ROOT/SAXTWebService

07 November, 2013

How to configure IIS for different port

Please click the link and view the post new domain : http://mahedee.net instead of this. I am not updating blog here. I am writing and updating blog in http://mahedee.net

1.      Open IIS Manager (run -> inetmgr)
2.      In the Connections pane, expand the Sites node in the tree, and then click to select the site for which you want to add/edit binding.
3.      Right click on the site and click Edit bindings
4.      Select Port on the site binding pane
5.      Click Edit button
6.      In Edit Site Binding pane type port (ex. 1080) and click Ok