Saturday, July 25, 2009

Sending mail with secure service layer in asp.net 3.5/2.0

In earlier post i have mentioned that how to send the email using new System.Net.Smtpmail with asp.net 2.0 or higher version. Now lets learn how to send the mail with the secure service layer in the asp.net.

Security is the one of the most important requirement in today’s world as you are doing your business online you have keep secure from other wrong elements. Secure service layer add an

extra layer of security to your web application and sending mail with the SSL with tighten your security for mails. Your emails are more secure then ever and your valuable information will not going to wrong hands.

Here is the code from which we can send the email with the secure service layer. As i have mentioned in earlier post you need to to send email with authentication to use SSL. So you need to write following code. First you need to create message like following..

MailAddress fromAddress = new MailAddress("[email protected]","Nameofsendingperson");
message.From = @”fromAddress”;//here you can set address
message.To.Add("mailto:[email protected]%22%29;//");//
message.Subject = "Sending email with ssl";
message.CC.Add("[email protected]");//ccing the same email to other email address
message.Bcc.Add(new MailAddress("[email protected]"));//here you can add bcc address
message.IsBodyHtml = true;//To determine email body is html or not
message.Body =@"Plain or HTML Text";
Then you have to sent message with following code.
System.Net.Mail.SmtpClient mailClient =
 new System.Net.Mail.SmtpClient("your smptp","ssl port");
//This object stores the authentication values
System.Net.NetworkCredential basicCrenntial = 
new System.Net.NetworkCredential("username", "password");
mailClient.Host = "Host";
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicCrenntial;
// You have to add one other properties for SSL
mailClient.EnableSSL=true;
mailClient.Send(message);
Share:
Friday, July 24, 2009

Client Id of a control in ASP.NET 4.0.

Client Id is used to store the id of a server control in client side. ASP.NET Engine creates a very long client id to unique identify each element on the same page. If you are having so many inner controls hierarchy then asp.net will generate very long client id like “ctl00_Ctl001_ctl02_BM_Login_btnSave” here i i have used control name like ctrl00,ctr001,bm etc. If you are having long control name then it will more longer then this. This will increase html kilobytes for the pages and if you are having so many server controls in the page then it will take time to load in browser and will decrease performance of application . To overcome this problem we have to override existing asp.net controls like textbox,label etc and then you have override client id from server side with server side id. Now with asp.net 4.0 you can control client id generated by .net framework. In asp.net 4.0 there is one another property called ClientIdMode which will control the behavior of client id generated by .net framework. Like following.

<asp:Button ID="btnSave" runat="server" ClientIDMode="[Mode]" />

There are four types of different mode for ClientIdMode property.

  1. Legacy- This is the same as in old version. It will generate client like like “ctl00_Ctl001_ctl02_BM_Login_btnSave” in old fashion.

  2. Inherit-This is the default mode for every control . It will refer parent control to have its clientidmode. If you want to change it then you have to specify your client id mode for that control.

  3. Static –This mode will put client id as static if you set server id like “btnSave” then it will generate the same ld like “btnSave”. So if you want to use this mode then you have to make sure that you are having all unique name in one pages. Otherwise it will be a mess for ids.

  4. Predictable- This mode will used when the framework needs to ensure uniqueness of each control in particular way. The framework traverse from the control to parent controls and put hierarchy of parent control id with control id like ‘”ctrl0_btnsave” and for another btnsave its like “ctrl0_ctrl1_btnsave” etc.

  5. Technorati Tags: ,
Share:
Thursday, July 23, 2009

Javascript is not working with update panel- Microsoft Ajax

As an asp.net developer we all must have to use update panel for the ajaxifying our application in today’s ajax world. No one likes postaback now. But when we add the some content with the java script under update panel then some times it’s stop working because of the update panel server side behavior. So what we should do? … Here is the trick. Normally we code java script in the asp.net page like following…

string alertScript = "javascript:alert('Alter From asp.net page')";
ClientScript.RegisterStartupScript(typeof(Page),"alertscript", alertScript);
Instead of this you should use.

string alertScript = "javascript: alert('This is aler from asp.net page')";
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript",
                                alertScript,true);
This will work. Happy coding..

Technorati Tags: ,,,,
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews