Wednesday, October 29, 2008

WebControl for creating charts

Check this Url.
http://www.carlosag.net/Tools/WebChart/

its an excellent free chart control to render charts in our application.

Redirecting to Custom Error Page When 404 Page not Found Occurs.

Write the below code in global.asax file in Application_Error Method.
StringBuilder errMessage = new StringBuilder();
Exception ex = Server.GetLastError();
if (ex is HttpException)
{
HttpException checkException = (HttpException)ex;

switch (checkException.GetHttpCode())
{
case 403:
{
errMessage.Append("You are not allowed to view that page.");
break;
}
case 404:
{
errMessage.Append("The page you requested cannot be found.");
break;
}
}
}

we can number of http code here.

Get the Previous Page Name

Below is the code to get page name from where it has been redirected to the current page.

code in the current page:

if (Request.UrlReferrer != null)
{
string PName = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
Response.Write("Redirected from : "+PName);
}


lazer hair removal

Thursday, October 23, 2008

Detecting Browser Pop up blocker.

Below is the javascript code to detect the popup blocker of a browser
<script language="javascript">
function popupblocker()
{

var sOption="toolbar=no,location=no,directories=no,menubar=no,";
sOption+="scrollbars=yes,width=500,height=500,left =200,top=50";
var i=window.open("Somepage.aspx","",sOption);

if(!i)
alert("Your browser Popup is on,Please turn off to open the child window.")


}

</script>

call this function on body load.

<body onload="popupblocker()">
</body>

Tuesday, October 21, 2008

Getting Image coordinates on mouse move.

<html>
<head>
<script language="JavaScript">
function point_it(event)
{
pos_x = event.offsetX;
pos_y = event.offsetY;
document.pointform.form_x.value = pos_x;
document.pointform.form_y.value = pos_y;
}
</script>
</head>
<body>
<form name="pointform" method="post">
<img src="Sunset.jpg" id="cross" onmousemove="point_it(event)"/>
You pointed on x = <input type="text" name="form_x" size="4" /> - y = <input type="text" name="form_y" size="4" />
</form>
</body>
</html>

Thursday, October 16, 2008

Images Resize

Below is code to resize the image in terms of its height and width and also its filesize.


System.Drawing.Image src_image = System.Drawing.Image.FromStreamFileUpload1.PostedFile.InputStream);

Bitmap bitmap = new Bitmap(Width,Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

bitmap.SetResolution(src_image.HorizontalResolution, src_image.VerticalResolution);

Graphics new_g = Graphics.FromImage(bitmap);

new_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

new_g.InterpolationMode = System.Drawing.Drawing2.InterpolationMode.HighQualityBicubic;

new_g.DrawImage(src_image, 0, 0, bitmap.Width, bitmap.Height);

src_image.Dispose();

bitmap.Save(Server.MapPath(URL) + FileUpload1.FileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);

bitmap.Dispose();

new_g.Dispose();


The Above Code is for Only Jpegs.

List of Connection strings for different Databases from .Net

Ms-Access :

Provider=Microsoft.Jet.OLEDB.4.0DataSource=C:\mydatabase.mdb;UserId=admin;Password=;


Sql server :
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

My Sql :
Provider=MySQLProv;Data Source=mydb;User Id=myUsername;Password=myPassword;

Oracle :
Provider=msdaora;DataSource=MyOracleDB;UserId=myUsername;Password=myPassword;

For More Connection Strings Click Here

About Sql server Injection through Query strings.

ASCII Encoded/Binary String Automated SQL Injection Attack

Check out the below link to know more how it works.

http://www.bloombit.com/Articles/2008/05/ASCII-Encoded-Binary-String-Automated-SQL-Injection.aspx

Indexes in Sql server

Indexes in SQL server are similar to the indexes in Books.
They help SQL server retrieve the data quickly.

There are clustered and nonmclustered indexes.

A clustered indexes is a special type of index that records the way in which records in the tableare physically stored.Therefore , table can have only one clustered index.The leaf nodes of a clustered index contain the data pages.

A nonClustered index is a special type of index in which the logical order of the indexdoes not match the physical stored order of the rows on disk.The leaf node of a non clustered index dows not consist of the data pages .Instead the leaf nodes contain index rows.
The syntax for creating indexes

CREATE INDEX idxModelON Product (Model)

Let's assume that we have the following table,

TABLE Customer
(
First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
Birth_Date date)


and we want to create an index on the column Last_Name, we would type in,

CREATE INDEX IDX_CUSTOMER_LAST_NAMEon CUSTOMER (Last_Name)[/COED]

If we want to create an index on both City and Country, we would type in,

CREATE INDEX IDX_CUSTOMER_LOCATIONon CUSTOMER (City, Country)