-(unichar) fn: (unichar)n{ return n ^ 0xFFFF004B == 0? n : [self fn:(n-0x1)]}

ASP.NET MVC Whole Site 301 Permanent Redirect

August 12th, 2010

For some reasons, we need to permanently redirect the whole website to another website. It would be much easier that you are the owner of the server. But most of time you just host your website on the server out there. It wouldn’t be a big problem that your hosting company will support you to do some simple 301 redirect or may you have enough privilege to do it yourself. Is it possible to redirect permanently the website to other website by programming a little bit?

Sure you can. With MVC routing facilities, you can define your customized redirect logic: CREATE AN EMPTY MVC PROJECT, MODIFY GLOBAL.ASPX.CS FILE ONLY ON THIS EXAMPLE:

First of all, define two objects which implemented IRouteHandler and IHttpHandler, you can feel free to define those two objects on Global.aspx.cs file:

//@Implements IRouteHandler
class RedirectRouteHandler : IRouteHandler
{
private string newUrl;
public RedirectRouteHandler(string newUrl) { this.newUrl = newUrl; }
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new RedirectHandler(newUrl);
}
}

//@object implements IHttpHandler
class RedirectHandler : IHttpHandler
{
private string newUrl;

public RedirectHandler(string newUrl) { this.newUrl = newUrl; }

public bool IsReusable { get { return true; } }

public void ProcessRequest(HttpContext httpContext)
{
httpContext.Response.Status = “301 Moved Permanently”;
httpContext.Response.StatusCode = 301;
httpContext.Response.AppendHeader(“Location”, newUrl);
return;
}
}

Then add one line on RegisterRoutes(RouteCollection routes) method (in Global.aspx.cs):

routes.Add(new Route(“{*pathInfo}”, new RedirectRouteHandler(@”http://koumei.net”));

Now all request to the website will redirect to “koumei.net” permanently. :)

Bookmark and Share


Koumei New Domain!

July 31st, 2010

Koumei got a new personal domain: koumei.co which is the same as koumei.net though. :)

Gonna make a page: koumei.co/ol :) cool !

Bookmark and Share


Html5 Drama Update Episode 2

July 27th, 2010

Html5 Drama Episode 2

Foreword:

Anonymous’ ID seems to be unveiled on this update. Well, the anonymous sends Koumei a photo image, Koumei is shocked after he knows who anonymous really is.

Summary:

2D context API is quite useful and interesting. The HTML5 canvas is absolutely fantastic!

Pre-requisition:

Firefox 3.6+ or Google Chrome. Internet Explorer 8 does not support

Bookmark and Share


An Experimental Html5 Drama

July 25th, 2010

After reading through all useful articles about Html5 and CSS3, I try to create a new Html5 template for my blog. If you would like to see something new about html5 and css3, have a look at this article:
70 Must-Have CSS3 and HTML5 Tutorials and Resources

Koumei’s experimental page is available here: http://koumei.net/html5.html

Nothing much currently. I am quite interested in creating the gradient background and rounded corner.

This page will be kept updating.

Bookmark and Share


Say Hello to koumei.net on HelloVPS

July 23rd, 2010

Yesterday koumei.net was condemned due to bring down the whole hosting server for harmful scripts, according to the server support. Not easy to contact them since they are in states. I am desperate to stay on their server without any secure. I would rather move to another server than to explain I am innocent. So I will move out from their server, I don’t like their service as well. How come they close down my website so suddenly without 1 day or 2 days notice?

Thanks to Howie from states who provides me a shelter at this moment. koumei.net is homeless, desperate and depressed last night, but because of his kindly help that make me home again. Now let us say hello to koumei.net again on HelloVPS (HelloVPS.com).

hellovps

hellovps

Bookmark and Share


Champagne Flutes with Heart and Crystal Drop

June 26th, 2010

Champagne Flutes with Heart and Crystal Drop - Set of 2

Champagne Flutes with Heart and Crystal Drop - Set of 2


$49.99 ONLY [$39.99 + $10 (Shipping fee)]


Don’t know what to buy for your friend’s wedding party? Here is an ideal gift for your friend! Brand new and looks gorgeous! Can’t afford to lose the chance. Only sale on Koumei.net

Flat rate shipping fee, only AU$10

Bookmark and Share


MVC2 Bug on Data Binding in Listbox?

June 23rd, 2010

Seems MVC and MVC 2 don’t realize that there is an issue when binding the data on the view:

Given an extension on HtmlHelper: this extension will generate a list box in view based on the collection “cakes”. (Because I like cake, so I use dessert object as example :)

public static MvcHtmlString MyDropDownList(this HtmlHelper target, string controlName, IQueryable<Cake> cakes, object htmlAttr)
{
if (cakes== null)
return MvcHtmlString.Empty;
var cakesList = new SelectList(cakes, “Id”, “CakesName”);
return target.ListBox(controlName, cakesList, htmlAttr);
}

It is okay, but the main issue is if the when I specify the Model data on control name, it IS SUPPOSED to generate the list box with the data which retrieved from database are selected. Yes.聽 IT IS SUPPOSED TO BE. But, unfortunately, MVC fail to automatically bind data for us…聽 The data “cakesList” is showing properly, but with no preselect options. In most of the business logic, it’s not gonna work, because it is no point for user to re-select the options every time before save the data.

In this case, MVC is not gonna auto-bind the data for us, we just need to figure out another way to display and manipulate the data properly. So we will change something on the extension, view and the controller:

1. On the view, don’t specify the name to model’s name, For example, the data which will be weaved to list box is CakeViewData.CakeList, the data related to database is CakeViewData.Dessert.Cakes. Normally, we will use the extension to weave the data:

<%=Html.MyDropDownList(“Dessert.Cakes”, Model.CakeList, new { @class = “multiselect”, size = 5 })%>

Since MVC is not gonna take care of the data binding, The name (on parameter controlName) should and NEED to use other name instead. Change “Cakes” to any other name, for example, change to “MyCakes”:

<%=Html.MyDropDownList(“Dessert.MyCakes”, Model.CakeList, new { @class = “multiselect”, size = 5 })%>

2. Extension is changed to:

public static MvcHtmlString MyListBoxWithSelectedList(this HtmlHelper target, string name, IQueryable<Cake> cakes, List<string> selected, object htmlAttr)
{
if (interests == null)
return MvcHtmlString.Empty;
var cakeList = new MultiSelectList(cakes, “Id”, “CakeName”, selected);
return target.ListBox(name, cakeList, htmlAttr);
}

I just add a parameter “List<string> selected” in the extension which will be used in MultiSelectList object that can be bind to the the items to be selected.

3. In controller, before saving the data, need to use FormCollection or Request["Dessert.MyCakes"] to obtain the data “MyCakes” manually.

string myCakes = Request["Dessert.MyCakes"];
Dessert dessert = new Dessert{Cake = myCakes};

It might not be a bug actually. And in this example you can feel how flexibility that MVC can bring you: the way to manipulate the model or data varies!聽 :)

Happy programming in MVC 2!

Bookmark and Share


Can’t Resist It! Yummy Egg Custard Almond Croissant

June 22nd, 2010

A picture is better than 1000 words:

Croissant and Vanilla Slices

Croissant and Vanilla Slices

When the creamy egg custards leaking from the croissant after first bite, can’t help yourself falling in love with the taste anymore.

Bookmark and Share


Koumei on Crumpler = Koumpler?

June 21st, 2010

Last month I got a very smart Crumpler bag from my company which is kind of award :-) I am glad that I have such a big stylish bag from now on.

And I found some badges are fitted my bag very well. So I just pin them on my bag, looks more smart, doesn’t it?

Have a close up:

Bookmark and Share


REMIX10 – Share the Web Love, Late Update

June 19th, 2010

I almost forget the interesting 2-day event or you can say “meeting” in Melbourne. The idea of this conference is to show Microsoft developer the latest development kits and to let technical or IT people catch up each other. $300 for joining the meeting but I got it for free. Thanks to my boss to give me such great opportunity to join the great event.

I got 2 souvenirs, such as t-shirt, caps, but all are related to Microsoft stuff. You want to get the t-shirt? well, need to make some efforts. Everyone who attends the meeting will get a magic cube from the host, and need to fix the cube to a designated image. After all, once cubes are fixed, the host sorts them out and put them in a frame, to shape a IE icon:

The Frame of Magic cubes

The Frame of Magic cubes,Everyone is involved

I think the most useful sessions are about how jQuery works peacefully with ASP.NET and VS.NET 2010 new features, and one interesting session talking about the future data representation, and introduce Pivot. Microsoft considers the cooperation with jQuery is a giant step forward, and shows its ambitions to open source community. Microsoft starts to contribute to open source community and make a lot of effort towards it, look forward to seeing its powerful tool released in months to come.

Frankly Speaking - Talk Show in REMIX10

Frankly Speaking - Talk Show in REMIX10

One thing somehow a little bit disappointed me is on this event, Microsoft doesn’t show any thing about HTML5 and CSS3, I think because Microsoft more focuses on sliverlight technology?

Bookmark and Share


Profile

Submit Your Site To The Web's Top 50 Search Engines for Free!