Archive for August, 2008
IIS: Redirection from non-www to www domain
Written by jf on August 8, 2008 – 6:00 am -The problem today, is that we have a great asp.net website but search engines are indexing the http://greataspnetwebsite.com instead of http://www.greataspnetwebsite.com, this is commonly seen on the web and there are several ways to archive a good result for making the non-www to www domain. This redirection should be a 301 Permanently Moved, otherwise you will might lose your search engine indexed page or become duplicate content for your non-www and www domain. Here are easy steps how to archive a quick and clean Permanent Redirection using IIS.
Consider the case where we already have a website in IIS called: greataspnetwebsite.com
- Go to IIS Manager
- Create a new website that point to the same directory as your existing one
- Select the newly created website, open the properties box
- In the option button “When connecting to this resource the content should come from” should be change to “A redirection to a URL“
- Specify the URL http://www.greataspnetwebsite.com
- Select the check box that says “A permanent redirection for this resource.”
Copy-Clone custom object in C#
Written by jf on August 5, 2008 – 6:00 am -This post relates how to Copy/Clone custom object in C# (Deep and Shallow Clone).
In this example I will be having a base class that all my custom object will be inheriting from.
Updates: After quiet some research on the subject i recently found some interesting articles on this subject and wanted to share them on this post.
Object Cloning Using IL in C#
This subject is inspired on a session I followed on the TechDays 2008,
that addressed the fact that IL (Intermediate Language) can be used to clone objects, among other things, and that it’s not evil at all, and it can be pretty performant also.You only have to see that you don’t overuse it tho, because otherwise the readability of your code is reduced, which is not a good thing for the maintenance.
And wrong usage of reflection (what IL is, or at least uses) can also result in poor performance.Read more:
http://whizzodev.blogspot.com/2008/03/object-cloning-using-il-in-c.html
C# Class For Making a Deep Copy Clone of an Arbitrary Object
Here is a C# class that can create a deep copy clone of an arbitrary object. The thing that’s special about it is that it should work for any class that extends it, so that you don’t need to re-write a custom clone() function for every child class (as it seems the C# framework creators would like). This does a deep copy so be careful about members that recursively include one another.
Another way of doing this would be to use serialization . . . I just personally thought the reflection package would be more elegant.
Read more:
http://www.thomashapp.com/node/106
C# Object Clone Wars
Cloning C# objects is one of those things that appears easy but is actually quite complicated with many “gotchas.” This article describes the most common ways to clone a C# object.
Shallow vs. Deep Cloning
There are two types of object cloning: shallow and deep. A shallow clone copies the references but not the referenced objects. A deep clone copies the referenced objects as well.
Clone C# Object using Serialization and De-serialization (Deep Clone)
In this example i’ll be using Serialization and De-Serialization to make a deep clone of the Person Class.
You must import the following namespaces to start with.
using System; using System.Text; using System.Xml; using System.Xml.Serialization; using System.Runtime.Serialization; using System.IO;
ASP.NET: HyperLink and Label without Id attribute
Written by jf on August 4, 2008 – 6:00 am -Today, I’ll talk a bit about how ASP.NET handles HTML rendering of controls such as <asp:HyperLink> and <asp:Label>. If you have developed using ASP.NET you must have noticed that when an <asp:Hyperlink> or <asp:Label> is rendered you will find something like that:
<html> <a id="ctl00_ContentPlaceHolder1_rptShoppingCart_ctl00_lnkGotoCheckout" href="#" class="someCss">delete</a> </html>
From an ASP.NET point of view, this is fine, since all object rendered should be identified uniquely on the client side. But many a time these are useless, since these hyperlinks are not used to trigger any server side events. Thus the id attributes just takes up a lot of space on your HTML and Page Size when you have many links like that. If you don’t want to have those, here is a solution I came up with, you can create custom server controls that inherits from the control that you want to remove the id attribute tag from.
Here is sample of the code that i used to remove the id attribute from the Hyperlink Control, without basically removing all the features provided by the Hyperlink control such as being able to handle Resource files for globalization.
[ToolboxData("<{0}:HyperLinkEx runat=server></{0}:HyperLinkEx>")]
public class HyperLinkEx: System.Web.UI.WebControls.HyperLink
{
private string rel;
/// <summary>
/// Gets or sets the rel.
/// </summary>
/// <value>The rel.</value>
public string Rel
{
get { return rel; }
set { rel = value; }
}
/// <summary>
/// Renders the control to the specified HTML writer.
/// </summary>
/// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"></see> object that receives the control content.</param>
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
sb.Append("<a");
if (this.NavigateUrl.StartsWith("~"))
this.NavigateUrl = ResolveClientUrl(this.NavigateUrl);
sb.Append(" href=\"" + this.NavigateUrl + "\"");
if (!string.IsNullOrEmpty(rel)) sb.Append(" rel=\"" + rel + "\"");
if (!string.IsNullOrEmpty(this.CssClass)) sb.Append(" class=\"" + this.CssClass + "\"");
if (!string.IsNullOrEmpty(this.Target)) sb.Append(" target=\"" + this.Target + "\"");
if (this.Attributes["onclick"] != null) sb.Append(" onclick=\"" + this.Attributes["onclick"] + "\"");
sb.Append(">");
if (!string.IsNullOrEmpty(this.ImageUrl)) //Some image were found
{
if (this.ImageUrl.StartsWith("~"))
this.ImageUrl = ResolveClientUrl(this.ImageUrl);
sb.Append("<img src=\"" + this.ImageUrl + "\" alt=\"" + this.Text + "\" title=\"" + this.Text + "\" border=\"0\" />");
}
else
{
sb.Append(this.Text);
}
sb.Append("</a>");
writer.Write(sb.ToString());
}
}
In this source code, i have overridden the render method of the control and outputted a cleaner HTML anchor with no Id attributes. I have also added support for ImageURL attribute of the hyperlink server control, thus maintaining the most of the asp:Hyperlink features.
I have also created a tiny library with some controls: <asp:HyperLink>, <asp:Label>, <asp:Image> which i think are the controls that need not have the id attribute in every scenario.
You can find it for download under GNU Public Licence here.
Fatal error: require_once() [function.require]: Failed opening required ‘Text/Diff/Renderer.php’
Written by jf on August 2, 2008 – 10:24 pm -Was just trying to view one of my post that i modified once after being published and bumbed up with a page with these error messages:
Warning: ini_set() has been disabled for security reasons in /home/wacdesig/public_html/wp-includes/pluggable.php on line 1517
Warning: require_once(Text/Diff/Renderer.php) [function.require-once]: failed to open stream: No such file or directory in /home/wacdesig/public_html/wp-includes/Text/Diff/Renderer/inline.php on line 17
Fatal error: require_once() [function.require]: Failed opening required ‘Text/Diff/Renderer.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/wacdesig/public_html/wp-includes/Text/Diff/Renderer/inline.php on line 17
Apparently this is due to my hosting provider that have disabled the use the the PHP function ini_set(). Great !!! how do i edit post that i have edited before… fortunately i found out someone that came up with a solution :).
Please note that this issue is only for WP 2.6 and is cause by the new Revision module that allows you to view a revision of your post before it was edited.
Here is the link to the solution for this problem:http://www.code-styling.de/english/wordpress-26-and-the-textdiff-fatal-errors
I also found another solution for those who don’t want to download the modified WP source file that is proposed in the first solution
Edit the wp-includes/Text/Diff.php, line 52 :
require_once ABSPATH . WPINC . '/Text/Diff/Engine/' . $engine . '.php';
Edit the wp-includes/Text/Diff/Renderer/inline.php, line 17 :
require_once ABSPATH . WPINC . '/Text/Diff/Renderer.php';



Shout Box RSS Feed



