Thursday, February 9, 2012

LINQ SQL Injection

http://msdn.microsoft.com/en-us/library/bb399403.aspx

http://csharp-codesamples.com/2009/05/preventing-sql-injection-using-linq/

reading data through Excel

private DataTable ReadExcelData(string strFilePath, string strFileType)

{

DataTable dt = new DataTable();

try

{

if (strFileType.ToLower().Contains("xls") || strFileType.ToLower().Contains("xlsx"))

{

OleDbCommand excelCommand = new OleDbCommand();

OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();

// for office 2003 and prior versions

//////////string excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + strFilePath + "; Extended Properties =Excel 8.0;";

/////// for office 2007 onwards and prior versions

string excelConnStr = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + strFilePath + "; Extended Properties =Excel 12.0;";

// Microsoft.Jet.OLEDB.4.0 driver is only for uploading Microsoft-Excel 2003 and earlier versions.

OleDbConnection excelConn = new OleDbConnection(excelConnStr);

excelConn.Open();

DataTable dtSheetName = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

if (dtSheetName != null && dtSheetName.Rows.Count > 0)

{

string strSheetName = dtSheetName.Rows[0]["TABLE_NAME"].ToString();//gives first sheetname in the excel

excelCommand = new OleDbCommand("SELECT * FROM [" + strSheetName + "]", excelConn);//excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);

excelDataAdapter.SelectCommand = excelCommand;

excelDataAdapter.Fill(dt);

}

excelConn.Close();

}

}

catch (Exception objEx)

{

throw objEx;

}

finally

{

//Delete the saved file from server path after reading the data from the path.Because it is uploaded from client machine to database.We are saving to server to avoid errors.After process we are deleting here.

if (File.Exists(strFilePath))

File.Delete(strFilePath);

}

return dt;

}

shivprasad koirala URLS on WCF

http://www.codeproject.com/KB/WCF/WCFTransactions.aspx

http://www.codeproject.com/KB/WCF/WCFFAQPart5.aspx

http://www.codeproject.com/KB/aspnet/WCF.aspx

http://www.codeproject.com/KB/aspnet/WCFPart2.aspx

http://www.codeproject.com/KB/WCF/WCFFAQPart3.aspx

http://www.codeproject.com/KB/WCF/WCFTracingFAQ.aspx

sending emails through c# asp.net

web.config entry

<system.net>
<mailSettings>
<smtp from="yoursenderemail@corporate.com">
<network host="hostname" port="25" password="Password"
userName="PASSPORT2" defaultCredentials="false" /> </smtp>
</mailSettings>
</system.net>

Note: 1) Make sure from address domain name
2) IP address, port number should be valid

c# code

SmtpSection mailSettings = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
MailMessage MyMessage = new MailMessage();

string sendTo = this.txtEmailHard.Text;
string sendFrom = mailSettings.From;
string sendMessage = "hello now the time is : " + DateTime.Now.ToLongDateString();
MyMessage.To.Add(sendTo);
MyMessage.From = new MailAddress(sendFrom);
MyMessage.Subject = "Hi Welcome to eProfile";
MyMessage.Body = sendMessage;
MyMessage.IsBodyHtml = true;

this.lblComment.Text = mailSettings.Network.Host + " " + mailSettings.Network.Port;

SmtpClient emailClient = new SmtpClient(mailSettings.Network.Host, mailSettings.Network.Port);
if (mailSettings.Network.DefaultCredentials)
{
emailClient.UseDefaultCredentials = true;
}
else
{
emailClient.Credentials = new System.Net.NetworkCredential(mailSettings.Network.UserName, mailSettings.Network.Password);
}

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
emailClient.Send(MyMessage);
return;
}
catch (SmtpException smtpx)
{
throw smtpx;
}
catch (Exception ex)
{
throw ex;
}

sending emails through c# asp.net code

web.config entry




userName="PASSPORT2" defaultCredentials="false" />




Note: 1) Make sure from address domain name
2) IP address, port number should be valid

c# code

SmtpSection mailSettings = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
MailMessage MyMessage = new MailMessage();

string sendTo = this.txtEmailHard.Text;
string sendFrom = mailSettings.From;
string sendMessage = "hello now the time is : " + DateTime.Now.ToLongDateString();
MyMessage.To.Add(sendTo);
MyMessage.From = new MailAddress(sendFrom);
MyMessage.Subject = "Hi Welcome to eProfile";
MyMessage.Body = sendMessage;
MyMessage.IsBodyHtml = true;

this.lblComment.Text = mailSettings.Network.Host + " " + mailSettings.Network.Port;

SmtpClient emailClient = new SmtpClient(mailSettings.Network.Host, mailSettings.Network.Port);
if (mailSettings.Network.DefaultCredentials)
{
emailClient.UseDefaultCredentials = true;
}
else
{
emailClient.Credentials = new System.Net.NetworkCredential(mailSettings.Network.UserName, mailSettings.Network.Password);
}

emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
emailClient.Send(MyMessage);
return;
}
catch (SmtpException smtpx)
{
throw smtpx;
}
catch (Exception ex)
{
throw ex;
}

Thursday, February 2, 2012

multiple end points scenario

---------------
Project Manager
---------------
Method 1
Method 2
Method 3
Method 4

---------------
Project Leader
---------------
Method 5
Method 6
Method 7

---------
Developer
---------
Method 8
Method 9
Method 10


End points - PMEndPoint - A B C
End points - PLEndPoint
End points - DevEndPoint

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IPMService

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IPLService

Address - http://localhost/MobileApps/Service1.svc
Binding - WSHttpBinding
Contract - IDevService

public interface IPMService
{

Method 1
Method 2
Method 3
Method 4

}

public interface IPLService
{

Method 5
Method 6
Method 7

}

public interface IDevService
{

Method 8
Method 9
Method 10

}

what is data center

A data center is a facility used to house computer systems and associated components, such as telecommunications and storage systems. It generally includes redundant or backup power supplies, redundant data communications connections, environmental controls (e.g., air conditioning, fire suppression) and security devices.

Tier Level 1 - 99.671% availability
Tier Level 2 - 99.741% availability
Tier Level 3 - 99.982% availability
Tier Level 4 - 99.995% availability

IT operations are a crucial aspect of most organizational operations. One of the main concerns is business continuity; companies rely on their information systems to run their operations.

The boom of data centers came during the dot-com bubble. Companies needed fast Internet connectivity and nonstop operation to deploy systems and establish a presence on the Internet.

Installing such equipment was not viable for many smaller companies. Many companies started building very large facilities, called Internet data centers (IDCs), which provide businesses with a range of solutions for systems deployment and operation.

New technologies and practices were designed to handle the scale and the operational requirements of such large-scale operations. These practices eventually migrated toward the private data centers, and were adopted largely because of their practical results.