SEO oriented programming. (Part 1)

by OfirYaron 2/1/2010 9:45:00 AM

One of the most important things when publishing a website is exposure, there are many ways of bringing your site to public knowledge, advertisement is one of them, but a more basic and necessary way of doing so is optimizing the website to search engines. Without SEO planning and implementation your site may stay in the hidden web for a long time. 
As developers we encounter a wide range of SEO tools, some are free, some are pricy and many are open source and provide certain flexibility, referenced at the end are some of my favorites.
Most of these tools offer some good advices on a live site, but at that point, these changes are too costly to implement.
 
The first thing a good SEO'd (Yep, new word :) site needs is a Validated HTML. Invalid HTML may cost you on your page rank, such issues can be prevented beforehand while coding the HTML, so making sure you follow the W3C standard is preferred.
For example, a lot of GUI developers are not aware of the significance of… placing one  H1 per page or placing H tags in an incremental order.
Trying to fix such issues will take time and could result a massive change to the CSS and design…  sometimes produce even more bugs, as if the ones you already have are not enough.
 
Since implementing these changes or fixes is complicated after publishing a site, its mostly left undone.
Let's put down some ground rules to avoid this expensive refactoring:
 
1.  All the developers should be aware of SEO basics. Project managers are not the only ones to be concerned with promoting the site.
2.   Consult a SEO professional at the early stages of the project, allow them to code-review the HTML and fix the problems early (Or do-it-yourself and learn some SEO!).
3.  Use HTML validation tools as much as possible.
4.  Create sitemaps and make sure every page can be viewed without AJAX.


Tools:
Xenu - http://home.snafu.de/tilman/xenulink.html - Xenu's Link Sleuth (TM) checks Web sites for broken links and resolve page's meta data.
http://validator.w3.org/ - Single page HTML validation service.
http://tools.seobook.com/firefox/seo-for-firefox.html - SEO toolbar for Firefox.
http://tools.seobook.com – SEO help, the DOs and DON'Ts of SEO and plenty of tools to help you with SEO.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

SEO

GoDaddy IIS7 Pipleline Issues

by OfirYaron 1/13/2010 11:42:00 PM

I Recently uploaded a new homepage, built in .Net MVC (www.ofiryaron.com)

Trying to upload the new site to my GoDaddy hosting account I was facing a problem:

The account was preconfigured as an IIS 7 server with two pipeline choices: Classic Mode and Integrated Mode.

Classic mode behaves the same as IIS 6 and uses two piplines, one for native code and another for managed code,

Integrated mode uses a unified pipeline that allows an easier access to the request process points.

checking these two different pipeline modes I discovered that in the classic mode my blog (BlogEngine.Net) that is hosted on the same account on a subdomain is working well, but my MVC site will not proccess any request beside the homepage (homepage works well because of the default.aspx, while other requests should pass through the URL Routing that is failing for some reason)

Integrated mode does the opposite, the subdomain doesn't work well (Every URL including the subdomains go through the MVC rewrite rules I think) and the MVC site acts normal.

For now I cannot see how this could be resolved, the two different sites require two diffrent pipeline mode.

I'v contact GoDaddy to consult them with the issue and hopefully there will be an answer soon... for now I gave up on the homepage, bare with me.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

MVC

Linq with WCF

by OfirYaron 8/3/2009 7:51:00 AM

"An error occurred while receiving the HTTP response to
http://xxx/. This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server
(possibly due to the service shutting down). See server logs for more details."

Got this message while trying to communicate to a WCF service I’ve built,

My initial assumption was that I’m not using the suitable security binders at both sides (server and client) .

First thing I tried was striping down the authentication configuration to “none” – the same exception was still thrown.

Secondly I tried to remove the service functionality to most basic by returning null, It works, I’ve returned the functionality but kept returning null and guess what - still worked.

At this point it was clear that the is some problem with the object that I try to return, I assumed that my Linq to Sql objects were not Serialized, indeed that was the cause, if you’re having this exception and use Linq to Sql object as a returned object – Its probably it.

Here is a very helpful “how to” on the subject: http://www.west-wind.com/Weblog/posts/147218.aspx 

(All that need to be done is changing the DataContext Serialization Mode to Unidirectional)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

WCF

MVC ActionResult inheritance

by OfirYaron 7/19/2009 5:47:00 AM

MVC contains a nice class you can inherit inorder to return http responses other then a regular Render View:

bellow are three implementations I use the most:

ImageResult, TextResult and RssResult:

public class ImageResult : ActionResult

{

public Stream ImageStream { get; private set; }

public string ContentType { get; private set; }

public ImageResult(Stream imageStream, string contentType)

{

if (imageStream == null)

throw new ArgumentNullException("imageStream");

if (contentType == null)

throw new ArgumentNullException("contentType");

this.ImageStream = imageStream;this.ContentType = contentType;

}

public override void ExecuteResult(ControllerContext context)

{

if (context == null)

throw new ArgumentNullException("context");

HttpResponseBase response = context.HttpContext.Response;response.ContentType =

this.ContentType;

byte[] buffer = new byte[4096];

while (true)

{

int read = this.ImageStream.Read(buffer, 0, buffer.Length);

if (read == 0)

break;

response.OutputStream.Write(buffer, 0, read);

}

response.End();

}

}

public class TextResult : ActionResult

{

public string Content { get; private set; }
public TextResult(string content)

{

this.Content = content;

}

public override void ExecuteResult(ControllerContext context)

{

if (context == null)

throw new ArgumentNullException("context");HttpResponseBase response = context.HttpContext.Response;

response.Write(Content);

response.End();

}

public class RssResult : ActionResult

{

public SyndicationFeed Feed { get; set; }

public RssResult() { }

public RssResult(SyndicationFeed feed)

{

this.Feed = feed;

}

public override void ExecuteResult(ControllerContext context)

{

context.HttpContext.Response.ContentType =
"application/rss+xml";

Rss20FeedFormatter formatter = new Rss20FeedFormatter(this.Feed);

using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))

{

formatter.WriteTo(writer);

}

}

}

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

MVC

Saving objects to the registry

by OfirYaron 4/27/2009 7:49:00 AM

I've needed a way to save a complex object to the registry so I've wrote this class,

basically it uses reflection in order to find the properties of a generic type that was given and fill them in with the matching (by name) key on the registry.

public class RegistrySmartAgent

{

public string BasePath { get; private set; }public RegistrySmartAgent(string basePath)

{

BasePath = basePath;

}

private T ReadSingle<T>(string fullPath) where T : new()

{

RegistryKey key = Registry.LocalMachine.OpenSubKey(fullPath);

T t = new T();

foreach (string name in key.GetValueNames())

{

Type typeInfo = typeof(T);

PropertyInfo propertyInfo = typeInfo.GetProperty(name);

if ((propertyInfo != null) &&

(propertyInfo.PropertyType == typeof(int)) ||(propertyInfo.PropertyType ==

typeof(string)) ||

(propertyInfo.PropertyType == typeof(double)))propertyInfo.SetValue(t, key.GetValue(name),

null);

}

return t;

}

public IDictionary<string, T> Read<T>(string subName) where T : new()

{

RegistryKey key = Registry.LocalMachine.OpenSubKey(BasePath + "\\" + subName);

IDictionary<string,T> retList = new Dictionary<string,T>();

foreach (string name in key.GetSubKeyNames())

{

retList.Add(name,ReadSingle<T>(BasePath +
"\\" + subName + "\\" + name));

}

return retList;

}

public bool Write<T>(string subName, T element)

{

Type typeInfo = typeof(T);

PropertyInfo[] properties = typeInfo.GetProperties();

foreach (PropertyInfo propertyInfo in properties)

{

RegistryKey key = Registry.LocalMachine.OpenSubKey(BasePath + "\\" + subName);

if (key==null)key =

Registry.LocalMachine.CreateSubKey(BasePath + "\\" + subName);key.SetValue(propertyInfo.Name, propertyInfo.GetValue(element, null));

}

return true;

}

}

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Sanitize YouTube embed objects

by OfirYaron 4/20/2009 5:56:00 AM

It's contributing alot to a blog or a site when one allows embedding youTube videos to the posts or comments,

the real down-side is that by doing so you have to take into considiration the breach of cross side scripts that the object tag allows.

so for that matter I wrote a Regular expression that validate the input and retrive the URL from within the embed tag, then I placed it on a template tag that I know is safe,
By doing so you can even control the panel color and size that best suit you site.

here is how it works:

private string SanitizeYouTubeObject(string input)

{

//You Tube object Regular Expression

Regex youTubeObjExp =

new Regex(

@"(<embed\ssrc=""http://www.youtube.com(?<Url>[\w\d\s\p{L}\p{S}:#@%/~_?\+-=\\\.&’]+(?=""))([\w\d\s\p{L}\p{S}:""#@%/~_?\+-=\\\.&’]+)(></embed>))",

RegexOptions.IgnoreCase);

if (youTubeObjExp.IsMatch(input))

{

Match match = youTubeObjExp.Match(input);

string videoObject = string.Format(

@"<object width=""480"" height=""385""><param name=""movie"" value=""{0}""></param><param name=""allowFullScreen"" value=""true""></param><param name=""allowscriptaccess"" value=""always""></param><embed src=""{0}"" type=""application/x-shockwave-flash"" allowscriptaccess=""always"" allowfullscreen=""true"" width=""480"" height=""385""></embed></object>", "http://www.youtube.com" + match.Groups["Url"].Value);

//Return the sanitized Tag

return videoObject;

}

//In case it wasn't a legit Object Tag

return null;

}

 

its a simple example only to pass the idea.

A real generic solution will take a dictionary of known embed regexs (youTube, MySpace, etc...) and sanitize any given input accordinly, that way you allow a closed list of well know sites and the DB doesn't have to store the entire tag, the URL will be enough.

Currently rated 4.5 by 4 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Pagination on Linq to SQL

by OfirYaron 3/15/2009 5:49:00 AM

Paging on linq is so much easier then anything I've ever worked with.

consider the following code to add a generic GetPage method in case you use it on several Data Entities in your application:

public static T[] GetPage<T, K>(System.Data.Linq.Table<T> tableObject,

System.Linq.Expressions.Expression<Func<T, K>> orderPred,

int pageSize, int selectedPage) where T : class, new()

{

return tableObject.OrderByDescending(orderPred).Skip(pageSize * (selectedPage - 1)).Take(pageSize).ToArray();

}

public static void Test()

{

// Say this is my Users table:

//User(1,"Ofir")

//User(2,"Yaron")

//User(3,"Danny")

//User(4,"Gila")

//User(5,"Ran")

//User(6,"John")

//User(7,"Marry")

//User(8,"Shay")

//User(9,"Shula")

//User(10,"Moish")

//getting the second page - 4 objects

User[] point = GetPage<User, int>(Utilities.DB.Users, u => u.Id, 4, 2);

//returns:

//Ran

//John

//Marry

//Shay

}

 

Currently rated 4.5 by 4 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Where is that ActionLink!?!

by OfirYaron 2/25/2009 3:51:00 AM

I've been wrestling with MVC today.

I recently installed the RC after working with preview version for a while for some reason lots of my most favorite extended methods were gone after this installation.

So far I've tried re-installing the MVC RC package, overriding the dll manually, removing all the other assemblies from the web.config - leaving system.web.mvc the only one and nothing helped.

Oddly enough the object explorer show the ActionLink method on system.web.mvc.dll (namespace: system.web.mvc.html class:LinkExtensions) But all the insallisence give is a a short list that that seem to come from HtmlHelper but not those I need:

After playing with it a little - trying different assemblies I've found that the Extensions were moved to 'system.web.mvc.html', and the reason it didn't work was becouse the GAC was still holding an old version of that assembly (Preview 5)

Currently rated 4.3 by 3 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

MVC

Round Corner generator

by OfirYaron 2/14/2009 2:46:00 AM
This is a little function I've built that return an image of a round corner - by selecting the border color and the fill color, the nice thing is you can use it to generate a rounded corner on the fly in your web site, it's pretty fast!

public static Bitmap RoundedCorner(ContentAlignment position ,int height, int width, Color border, Color fill)
{
    Bitmap myBmpImage = new Bitmap(1, 1);

    // Create the graphics object
    Graphics myGraphics = Graphics.FromImage(myBmpImage);
    myBmpImage = new Bitmap(myBmpImage, new Size(width, height));
    myGraphics = Graphics.FromImage(myBmpImage);

    float pX = 0;
    float pY = 0;

    if ((position == ContentAlignment.BottomLeft) || (position == ContentAlignment.BottomRight)) pY -= height;
    if ((position == ContentAlignment.BottomRight) || (position == ContentAlignment.TopRight)) pX -= width;

    // Set Background color
    myGraphics.Clear(Color.Transparent);
    myGraphics.SmoothingMode = SmoothingMode.HighQuality;
    myGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

     if (fill != null)     
        myGraphics.FillEllipse(new SolidBrush(fill), pX, pY, width * 2, height * 2);

    if (border != null)
        myGraphics.DrawEllipse(new Pen(border), pX, pY, width * 2, height * 2);

    myGraphics.Flush();
    return (myBmpImage);
}
 

Ill upload test project later on to show how it works - right now you can pretty much copy-paste it.

Cheers,

Ofir 

 

Currently rated 4.7 by 7 people

  • Currently 4.714286/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

It's about time

by OfirYaron 2/12/2009 5:53:00 AM

Hi,

My name is Ofir Yaron and I'm a Brewer/.Net Developer

I'm .Net Developer for nine years now (C#) and worked before, for about five years with C++/VB/Delphi and many more icky languages :)

I recently started working with MVC and Linq after working with Monorail and ActiveRecords for a while, I still haven't decided which I hate more.

I've worked with web form before that – but I'm really trying to repress that period.

I opened up this blog to share programming issues that I deal with and think that they might interest someone else beside my-self and share my on growing knowledge and passion on Beer making.

You can email me to blog@ofiryaron.com for any interesting issue or problem you are facing, I'll be happy to dive in and try to help, and you are more than welcome to send me beer recopies, especially the Guinness recipe :)

 

Cheers

Ofir Yaron

Currently rated 4.7 by 7 people

  • Currently 4.714286/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Recent posts

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in