Saturday, March 20, 2010

Paragraph Trim function

 

 Trim your paragraph to limited number of words. A very useful function for designing text based websites like news or articles archives or list.

 

protected string paraTrim(string Input, int no_of_words)

    {

 

        // split input string into words (max 21...last words go in last element)

        String[] Words = Input.Split(new char[] { ' ' }, no_of_words);

 

        // if we reach maximum words, replace last words with elipse

        if (Words.Length == no_of_words)

            Words[no_of_words - 1] = "...";

        else

            return Input;  // nothing to do

 

        // build new output string

        String Output = String.Join(" ", Words);

        return Output;

 

    }


Monday, March 15, 2010

IIS URL Rewriting

IIS URL Rewriting

When a client makes a request to the Web server for a particular URL, the URL-rewriting component analyzes the requested URL and changes it to a different other URL on the same server. The URL-rewriting component runs very early in the request processing pipeline, so is able to modify the requested URL before the Web server makes a decision about which handler to use for processing the request.

IIS URL Rewriting
ASP.NET Routing

ASP.NET routing is implemented as a managed-code module that plugs into the IIS request processing pipeline at the Resolve Cache stage (PostResolveRequestCache event) and at the Map Handler stage (PostMapRequestHandler). ASP.NET routing is configured to run for all requests made to the Web application.

IIS URL Routing

Differences between URL rewriting and ASP.NET routing:

1. URL rewriting is used to manipulate URL paths before the request is handled by the Web server. The URL-rewriting module does not know anything about what handler will eventually process the rewritten URL. In addition, the actual request handler might not know that the URL has been rewritten.
2. ASP.NET routing is used to dispatch a request to a handler based on the requested URL path. As opposed to URL rewriting, the routing component knows about handlers and selects the handler that should generate a response for the requested URL. You can think of ASP.NET routing as an advanced handler-mapping mechanism.

In addition to these conceptual differences, there are some functional differences between IIS URL rewriting and ASP.NET routing:

1. The IIS URL-rewrite module can be used with any type of Web application, which includes ASP.NET, PHP, ASP, and static files. ASP.NET routing can be used only with .NET Framework-based Web applications.
2. The IIS URL-rewrite module works the same way regardless of whether integrated or classic IIS pipeline mode is used for the application pool. For ASP.NET routing, it is preferable to use integrated pipeline mode. ASP.NET routing can work in classic mode, but in that case the application URLs must include file extensions or the application must be configured to use "*" handler mapping in IIS.
3. The URL-rewrite module can make rewriting decisions based on domain names, HTTP headers, and server variables. By default, ASP.NET routing works only with URL paths and with the HTTP-Method header.
4. In addition to rewriting, the URL-rewrite module can perform HTTP redirection, issue custom status codes, and abort requests. ASP.NET routing does not perform those tasks.
5. The URL-rewrite module is not extensible in its current version. ASP.NET routing is fully extensible and customizable.

Tuesday, March 2, 2010

Create thumbnails for images in c#,Image size reduction, Decrease the size of images in c#

public byte[] imagereduce(System.Drawing.Image imgInput, int maxImageSize)
{

int tWidth;
int tHeight;
double widthHeightRatio = (double)imgInput.Width / (double)imgInput.Height;
// If width greater than height, then width should be max image size, otherwise height should be.
// Image should keep the same proportions.
//tWidth = maxImageSize;
//tHeight = (int)(maxImageSize / widthHeightRatio);
if (widthHeightRatio > 1.0)
{
tWidth = maxImageSize;
tHeight = (int)(maxImageSize / widthHeightRatio);
}
else
{
tWidth = (int)(maxImageSize * widthHeightRatio);
tHeight = maxImageSize;
}

//Session["imgheight"] = tHeight;
//Session["imgwidth"] = tWidth;

System.Drawing.Image.GetThumbnailImageAbort myCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

System.Drawing.Image myThumbnail = imgInput.GetThumbnailImage(tWidth, tHeight, myCallBack, IntPtr.Zero);
//myThumbnail.Save(Server.MapPath(sSavePath + sThumbFile));


System.IO.MemoryStream ms = new System.IO.MemoryStream();
myThumbnail.Save(ms, ImageFormat.Jpeg);
byte[] bitmapData = ms.ToArray();
return bitmapData;
}
public bool ThumbnailCallback()
{
return false;
}

Customized Message pop up Box in c# for websites

It gives you a pop up msgbox to show error messages or any alerts.

public Label msgbox(string text)
{
Label lbl = new Label();
lbl.Text = "";
return (lbl);
}

Friday, December 4, 2009

Tips on Web Hosting for High traffic websites

A high traffic web hosting plan is a plan that offers a very large amount of bandwidth and disk space and is suited for very busy sites where a lot of data is being added and retrieved.

A site with a lot of videos or high resolution photographs or a very active forum where messages are being posted all day long are prefect examples of web sites that could benefit from a high traffic hosting plan.

A hosting plan with high allowance for space and bandwidth will also prevent that shock of logging on to your web site and realizing that your site has been suspended for going for a bandwidth limit.

If that happens you either have to upgrade your account or pay extra to get the site online again or wait until a new month begins. Either way, visitors to your site will be turned off and may never return if they see your site is down.

What sites are appropriate for a high traffic plan?
A site offering videos or high resolution photos.
A very active message forum
Any site that with a large number of daily visitors and pageviews
Any combination of the above!

Tips on Web Hosting for High traffic websites

Simple Changes Doubled My Adsense Revenue

Several simple changes in my Adsense approach and layout have almost doubled my blog’s revenue. The results were so drastic and eye opening that I convinced a friend (www.oneprojectcloser.com) to make the same changes to his blog with even better results. The changes involve two simple ideas that can be easily incorporated into any Adsense monetized website or blog.

I’ve been blogging for over two years now and growing traffic, authority and readership slow and steady. Along with the steady increase in traffic the site has continued to increase it’s Adsense revenue at a similar pace with no sudden increases regardless of all the changes and adjustments I’ve made. That was true until I took the time to study many different published Adsense approaches. As I read all of these different approaches three distinct ideas came to the forefront.

Three Important Adsense Approaches

Less is More – This concept is really simple yet I hadn’t really given it much thought before. First off the top ad is the highest paying ad and you want that in the best possible position.
Secondly, if you’re using all three of the allotted Adsense units on a given page then there are quite a few ads all competing for attention or a click through. However, if you only use one Adsense unit then you’re limiting the number of ads served and improving the likelihood that one of those ads will get clicked. Therefore, the theory is that an advertiser will be willing to pay a higher rate for less competition.

Size Matters – If you read enough Adsense guides you’ll find that the 336 x 280 Large Rectangle is the most effective Adsense unit. It typically offers four ads and they are likely to be very related to the topic based on the position between the post title and body.
Position, Position, Position – Placing your Adsense unit above the fold is imperative for success. This makes sense to me for one reason. Every day my site (and I assume most sites) gets a majority of it’s traffic from search engines. This traffic is generated from people searching for something. So when they land on my page and they decide that it’s not the content they were looking for then I want them to see the Adsense unit right where they land so that becomes an “outclick” option.
How I Doubled My Adsense Revenue

In order to understand the approach I used to double my Adsense revenue I’ll use two graphics that show the same post before the changes and after the changes. First – the before shot:



My Old Adsense Layout Included:

468 x 60 Text Only Unit located in the header area of my page.
468 x 60 Text Only Unit located between the post title and the body of the post.
468 x 60 Text Only Unit located at the end of the post before the comment section.
Revised Adsense Layout Includes:

Remove the old 468 x 60 Text Only Unit completely and replaced with an affiliate banner. The idea here is to remove some of the units in order to address concept #1 of Less is More.
Replace the old 468 x 60 Text Only Unit with the 336 x 280 large rectangle unit. This unit is above the fold between the post title and body which makes it a very prominent position. This change addresses both of concept #2 and #3 for Size Matters and Position.
Remove the old 468 x 60 Text Only Unit completely. I actually replaced this with the new Chitika Jumbo unit which is also performing quite well. Again the removal helps address the Less is More concept.