Posts Tagged ‘Tips
SEO Friendly paging with Telerik RadDataPager and RadListView
Few days back I had the need to implement some mechanism for SEO friendly paging in my website gamefiz.com that allows users to play online flash games. I have that site running for quite sometime and adding features periodically as I get the time. Earlier version was on framework 3.5 which I upgraded to 4.0 without any trouble to take advantage of URL Routing for web forms introduced in ASP.NET 4.0 (more info here).
Background:
A page in the website “Leaderboard” had thousand of games and was built using MS DataList and for paging I used PagedDataSource. It was tedious and cluttering code I had to write, moreover it was a bit hard to implement SEO friendly paging.
So I decided to replace the old with Telerik controls and to my surprise it was a piece of cake, without much effort I was on track right away. DataList was replaced with RadDataListView and the pager code with RadDataPager. The pager offer you to generate search engine friendly URLs with routing by configuring some properties like “AllowSEOPaging” and “RouteName” defined in Global.asax file (that’s where you define your routes). So we now have these things to discuss:
RadPager
<telerik:RadDataPager runat="server"
ID="Pager" PagedControlID="dgGames" PageSize="35"
EnableTheming="false" CssClass="pager Paging" Skin="" AllowSEOPaging="true"�
AllowRouting="true" EnableEmbeddedSkins="false" RouteName="LeaderboardSeo"
RoutePageIndexParameterName="pager" SEOPagingQueryPageKey="CurrentPageKey">
<Fields>
<telerik:RadDataPagerButtonField PageButtonCount="20" FieldType="Numeric" FirstButtonText="First"
LastButtonText="Last" NextButtonText="Next" />
</Fields>
</telerik:RadDataPager>
RadListView
<telerik:radlistview ID="dgGames" runat="server" AllowCustomPaging="True" AllowPaging="true" OnNeedDataSource="dgGames_NeedDataSource"> <ItemTamplate></ItemTamplate> </telerik:radlistview>
The code behind:
protected void dgGames_NeedDataSource(object sender, Telerik.Web.UI.RadListViewNeedDataSourceEventArgs e)
{
int totalGames = 0;
int currentPage = Convert.ToInt32(Page.RouteData.Values["pager"] as string); // get the parameter
if (currentPage == 0) { currentPage = 1; }
//int startRowIndex = dgGames.CurrentPageIndex * Pager.PageSize;
int startRowIndex = (currentPage - 1) * Pager.PageSize;
int maximumRows = dgGames.PageSize;
List<Game> gamesList = GamesController.GetAllLeaderboardGames(startRowIndex, maximumRows, ref totalGames);
dgGames.DataSource = gamesList;
if (gamesList.Count == 0)
{
Response.Redirect("http://gamefiz.com", true);
}
dgGames.VirtualItemCount = totalGames;
int endText = (dgGames.PageSize * currentPage);
lblStart.Text = (startRowIndex + 1).ToString();
lblEnd.Text = endText > totalGames ? totalGames.ToString() : endText.ToString();
lblTotalGames.Text = totalGames.ToString();
}
just one piece left
Global.asax file:
routes.MapPageRoute("LeaderboardSeo", "leaderboard/p{pager}.html", "~/leaderboardgames.aspx", true,
new System.Web.Routing.RouteValueDictionary { { "pager", "1" } });
The route defines a single URL parameter with a default value of 1. This parameter will be used to specify the current page index in RadDataPager. To take advantage of this route setup the RadDataPager is configured to use this route. The route name and the name of the URL parameter that specifies the page index are set.
Summary
So folks I think it is fairly simple to get the whole concept of generating SEO friendly URL with RadDataPager. Excellent thing is that without no code (virtually) I was able to implement it easily. Please view working demo and share feedback.
URL Rewriting Tips
In one of my previous post I discussed about a simple and no-brainer solution to implement URL Routing/ Re Writing in ASP.NET 4.0 This post takes it a bit further by using the IIS7 Rewrite module and doing some basics right for search engines to index your pages properly. Here I will discuss to format you URL rewrite mechanism in a proper and SEO friendly way. These settings can be configured from the IIS7 Management Console/Website/URLRewriting Module and thus reflected eventually in web.config, but for simplicity I will happily present the direct code inserted in the config file.
To start with add a new section like this one under <system.Webserver>
<rewrite> <rules> </rules> </rewrite>
Tip 1: Add or Remove Trailing Slah
Trailing slash in a URL creates a situation that cause search engines to remember the URL as different and split the ranking, e.g there is a lot of difference in these: http://gamefiz.com and http://gamefiz.com/
This can be fixed by adding a rewrite rule that automatically directs the user to the predefined setting i.e with or without slash. I shall list both and you can decide which one to choose. So lets start with a rule for No Slash under the <rule> tag defined above.
<rule name="Remove Trailing Slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{URL}" pattern="WebResource.axd" negate="true" />
<add input="{URL}" pattern="ScriptResource.axd" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
To Add the slash at the end:
<rule name="Add trailing slash" stopProcessing="true">
<match url="(.*[^/])$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>
Tip 2: Default document rewrite
For ASP.NET users like myself this looks same: http://gamefiz.com and http://gamefiz.com/default.aspx as both are bound to display the same content, right? but for search engines its entirely different. To set a rule that anyone visiting http://gamefiz.com/default.aspx should automatically be shown http://gamefiz.com here is the tip
<rule name="Default Document" stopProcessing="true">
<match url="(.*?)/?Default\.aspx$" />
<action type="Redirect" url="{R:1}" />
</rule>
Tip 3: Casing URL
Yes it is important for search bots to have a uniform cased url, still a different case to have the URL in upper or lower case. This is also super easy with this rule to have small URL across the website:
<rule name="Lower Case URLs" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="WebResource.axd" negate="true" />
</conditions>
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
Tip 4: Canonical Hostnames
You may have noted situations where some websites open with www or without www prefix. If a website is opening for both this means trouble for search engines and will be treated as two separate URLs. This can be fixed with this trick
<rule name="Cannonical Hostname">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^gamefiz\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://gamefiz.com/{R:1}" />
</rule>
Summary
New URL Routing features in ASP.NET Web Forms 4 make it much easier to build applications that have more control over the URLs that are published. If you haven’t tested the IIS SEO Toolkit try it now!
For some more ways in initiating a SEO friendly website read this article for some tips.
SEO by a Developer’s point of view
Search engine optimization (SEO) is the process of improving the visibility of a website or a web page in search engines via the “natural” or un-paid (“organic” or “algorithmic”) search results. In general, the earlier (or higher ranked on the search results page), and more frequently a site appears in the search results list, the more visitors it will receive from the search engine’s users. SEO may target different kinds of search, including image search, local search, video search, academic search,[1] news search and industry-specific vertical search engines. (Wikipedia)
So what a developer should do?
Being a CEO (Chief Everything Officer) it is really hard to pace up with development, designing and maintaining a project, with a limited or no money to spend on hiring a SE optimizer one should learn the basic tricks to promote the website. I learned a lot with some of my websites like this blog and a flash based gaming website “gamefiz.com“. So here in this post I will discuss some steps to follow before really launching your website in production but please do not deploy unless you do the following.
1. SEO Toolkit for IIS7:
If your website is hosted under IIS then the first handy tool is to use the Search Engine Optimization Toolkit for IIS7. This can be downloaded from here. The toolkit includes the Site Analysis module, the Robots Exclusion module, and the Sitemaps and Site Indexes module, which let you perform detailed analysis and offer recommendations and editing tools for managing your Robots and Sitemaps files. This will help you rectify errors with ease and giving proper directions. Rather explaining the use myself I would be more happy in referring to this article by the maestro ScottGu.
2. Create a Google Analytics Account:
Google Analytics is the enterprise-class web analytics solution that gives you rich insights into your website traffic and marketing effectiveness. Powerful, flexible and easy-to-use features now let you see and analyse your traffic data in an entirely new way. With Google Analytics, you’re more prepared to write better-targeted ads, strengthen your marketing initiatives and create higher converting websites.
3. Create a Google Webmaster Account:
Improve your site’s visibility in Google search results. It’s free. Google Webmaster Tools provides you with detailed reports about your pages’ visibility on Google. To get started, simply add and verify your site and you’ll start to see information right away. Easy to create and easy to get acquainted.
4. Claim your site at Alexa:
Alexa provides information about websites including Top Sites, Internet Traffic Stats and Metrics, Related Links, Online Reviews Contact Information and Search. Alexa is a California-based subsidiary company of Amazon.com that is known for its toolbar and website. Once installed, the toolbar collects data on browsing behavior which is transmitted to the website where it is stored and analyzed and is the basis for the company’s Web traffic reporting. Alexa claims that 6 million people visit its website monthly
–
Above mentioned points are not the commandments really and I am novice in the field of SEO but still shared these steps as my personal expereince. Your comments and feedback are most welcome.
Older Post:
Call web service from Oracle PL/SQL
Call web service from Oracle PL/SQL
Hi Folks
In this post I will present a simple way of calling a webservice from your PL/SQL code. I would use a Function to do that.
Prerequisite:
First, download the latest copy of the dbwsclient.jar file:
- Pre 10g: dbws-callout-utility.zip (10.1.2)
- 10g: dbws-callout-utility-10R2.zip (10.1.3.0)
- 10g & 11g latest: dbws-callout-utility-10131.zip (10.1.3.1)
Extract the jar file from the zip file into the “$ORACLE_HOME/sqlj/lib” directory.
The jar file can be loaded into the SYS schema for everyone to access, or into an individual schema that needs access to the web client. To make sure you avoid errors during the load, set the JAVA_POOL_SIZE initialization parameter to at least 150M.
# Load into the SYS schema. export PATH=/u01/app/oracle/product/10.2.0/db_1/bin:$PATH cd /u01/app/oracle/product/10.2.0/db_1/sqlj/lib # 10gR2 loadjava -u sys/password -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb102.jar # 11g loadjava -u sys/password -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb11.jar # Load into an individual schema. export PATH=/u01/app/oracle/product/10.2.0/db_1/bin:$PATH cd /u01/app/oracle/product/10.2.0/db_1/sqlj/lib # 10gR2 loadjava -u scott/tiger -r -v -f -genmissing dbwsclientws.jar dbwsclientdb102.jar # 11g loadjava -u scott/tiger -r -v -f -genmissing dbwsclientws.jar dbwsclientdb11.jar
In Oracle 10g the UTL_DBWS package is loaded by default. In Oracle 9i and 11g the package must be loaded using the specification and body provided in the zip file. The execute privilege should be granted on the ULT_DBWSpackage to any users needing access to the functionality.
<pre>$ cd $ORACLE_HOME/sqlj/lib $ sqlplus / as sysdba SQL> @utl_dbws_decl SQL> @utl_dbws_body SQL> CREATE PUBLIC SYNONYM utl_dbws FOR sys.utl_dbws; SQL> GRANT EXECUTE ON sys.utl_dbws TO test;</pre>
So after doing the above stuff here is the code:
CREATE OR REPLACE
FUNCTION wsproxy_send_request
return varchar2
as
l_service SYS.UTL_DBWS.service;
l_call SYS.UTL_DBWS.call;
l_result ANYDATA;
l_wsdl_url VARCHAR2(32767);
l_namespace VARCHAR2(32767);
l_service_qname SYS.UTL_DBWS.qname;
l_port_qname SYS.UTL_DBWS.qname;
l_operation_qname SYS.UTL_DBWS.qname;
l_input_params SYS.UTL_DBWS.ANYDATA_LIST;
boolean_type_qname SYS.UTL_DBWS.QNAME;
string_type_qname SYS.UTL_DBWS.QNAME;
long_type_qname SYS.UTL_DBWS.QNAME;
begin
l_wsdl_url := 'http://<<host>>/syed/services/<<serviceName>>?wsdl';
l_namespace := 'http://<<namespace>>';
l_service_qname := SYS.UTL_DBWS.to_qname(l_namespace, '<<serviceName>>');
l_port_qname := SYS.UTL_DBWS.to_qname(l_namespace, '<<endPoint>>');
l_operation_qname := SYS.UTL_DBWS.to_qname(l_namespace, 'send');
l_service := SYS.UTL_DBWS.create_service (URIFACTORY.getURI(l_wsdl_url), l_service_qname);
l_call := SYS.UTL_DBWS.create_call (l_service, l_port_qname, l_operation_qname);
-- Data Types more can be found at: <a href="http://www.w3.org/TR/xmlschema-2/#built-in-datatypes">http://www.w3.org/TR/xmlschema-2/#built-in-datatypes</a>
string_type_qname := SYS.UTL_DBWS.to_qname('http://www.w3.org/2001/XMLSchema', 'string');
long_type_qname := SYS.UTL_DBWS.to_qname('http://www.w3.org/2001/XMLSchema', 'long');
-- The name of parameters in method of webservice e.g: public bool Add(long val1, long val2)
SYS.UTL_DBWS.add_parameter(l_call, 'val1', long_type_qname, 'ParameterMode.IN');
SYS.UTL_DBWS.add_parameter(l_call, 'val2', long_type_qname, 'ParameterMode.IN');
SYS.UTL_DBWS.SET_PROPERTY(l_call, 'SOAPACTION_USE', 'TRUE');
SYS.UTL_DBWS.SET_PROPERTY(l_call, 'SOAPACTION_URI', '');
SYS.UTL_DBWS.SET_PROPERTY(l_call, 'ENCODINGSTYLE_URI', '');
SYS.UTL_DBWS.SET_PROPERTY(l_call, 'OPERATION_STYLE', 'rpc');
-- set values preferably to be get from stored proc IN Params but hardcoded for example
l_input_params(0) := ANYDATA.ConvertNumber(1);
l_input_params(1) := ANYDATA.ConvertNumber(5);
-- set return type here Add returns Boolean value
sys.utl_dbws.set_return_type(l_call, boolean_type_qname);
l_result := SYS.UTL_DBWS.invoke(l_call, l_input_params);
SYS.UTL_DBWS.release_call (l_call);
SYS.UTL_DBWS.release_service(l_service);
RETURN ANYDATA.AccessVarchar2(l_result);
END;
So that’s it, please try and give feedback
Crop Image of selected area plus draw rectangle on Window Form
Hi
In this post I would discuss much of related code pieces that is to crop an image and save it of the dynamically drawn rectangle on a Win form. The picture is loaded in a Picturebox control you can hardcode it for a try or make another browse button to load the picture from some location. So lets first look at the crop method
private void btnCaptureImage_Click(object sender, EventArgs e)
{
try
{
if (!String.IsNullOrEmpty(m_sFileName) && !rtPictureBox.IsEmpty)
{
Bitmap bmp = Bitmap.FromFile(m_sFileName) as Bitmap; // where m_sFileName has the full image path
//Bitmap bmp = Bitmap.FromFile(pbForm.ImageLocation) as Bitmap; // you can use this property if the image in picture box image is loaded via "ImageLocation" property
Bitmap bmpCrop = bmp.Clone(rtPictureBox, bmp.PixelFormat);
bmp.Dispose();
bmpCrop.Save("d:\\cropped\crop1.jpg", ImageFormat.Jpeg);
bmpCrop.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Now for draw rectangle mechanism we have to handle 3 events of the picture box control that are: MouseDown, MouseMove and Paint like
/// <summary>
/// Initiates the rectngle draw point currently top left corner of the image
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbForm_MouseDown(object sender, MouseEventArgs e)
{
using (Graphics g = this.pbForm.CreateGraphics())
{
rtPictureBox = new Rectangle(e.X, e.Y, 0, 0);
pbForm.Invalidate();
}
}
/// <summary>
/// This records the mouse movement and stores the coordinates in a rectangle object declared at class level
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbForm_MouseMove(object sender, MouseEventArgs e)
{
// This makes sure that the left mouse button is pressed.
if (e.Button == MouseButtons.Left)
{
// Draws the rectangle as the mouse moves
rtPictureBox = new Rectangle(rtPictureBox.Left, rtPictureBox.Top, Math.Abs(e.X - rtPictureBox.Left), Math.Abs(e.Y - rtPictureBox.Top));
}
pbForm.Invalidate();
}
/// <summary>
/// This drwas the red marker around the selected area to be cropped
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbForm_Paint(object sender, PaintEventArgs e)
{
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rtPictureBox);
}
}
So that is the meat and bones for this exercise, please share your comments and thoughts
Check if form is already running – Winform
To check for a particular form whether it is running or not, one can query the Application.OpenForms that gets a collection of open forms owned by the application. When a form is opened it is added to this collection.
Create a boolean method that check the opened state of the supplied form in parameter:
private bool CheckForm(Form form)
{
bool bIsRunning = false;
foreach (Form f in Application.OpenForms)
{
if (form == f)
{
bIsRunning = true;
}
}
return bIsRunning;
}
For example:
// if frmOrders is not open
if (!CheckForm(frmOrders))
{
// code goes here
}
Regards, please don’t hesitate to post comment and questions.

MCTS:ASP.Net 3.5 

