Clicky

Following my previous posts on How to handle non-English characters in ASP.NET MVC routes, Build pretty clean URL for your dynamic pages using JavaScript and Non English Words in URL I decided to share another simple tip that let you translate what your user inserts as content’s title (that can be a blog post title, a page name or a news headline) automatically using Google Translate API.

Let me explain it with an example. Suppose that you have a news system in Persian language and your end user enters a Persian phrase like “این یک عنوان خبر است” as the headline of a news story. From SEO point of view it’s better we include original headline words in URL (like something that I explained in this post) instead of using an integer ID or GUID (e.g. /news/?id=1 or /news/1.aspx, etc.) but as we discussed on in that post, including non-English characters in URLs is not the best way! I just wanted to have something like /news/story/this-is-a-title and didn’t want to force user translate his words into English in order to use in URL field.

A few days ago I was thinking on this topic and decided to try a trick to utilize Google Translate API (which has recently started supporting Persian language as well) to translate such titles into meaningful English phrases and then clean them using the way I described in this post.

Fortunately, thanks to Google API simplicity it was so easy and straightforward. Here’s what I wrote:

  1. First you should include Google API JavaScript source in your page:
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  2. Add this JavaScript code to your page:
    $(document).ready(function() {
            $("#contentPage_Title").blur(function() { parseUrl($("#contentPage_Title").val()) });
        });
    
    
            google.load("language", "1");
            function parseUrl(url) {
                $("#loadingImage").attr("style", function() { return "display: inline;" });
                google.language.translate(url, "fa", "en", function(result) {
                    if (!result.error) {
                        var url = (result.translation + " ").replace(/[^a-zA-Z0-9]+/g, "-");
                        $("#contentPage_Url").val(url.slice(0, url.length - 1).toLowerCase());
                        $("#loadingImage").attr("style", function() { return "display: none;" });
                    }
                });
            } 
    
    

You’re done! Now, let me explain the code a little. First using jQuery, you tell the DOM to fire parseUrl() event as soon as you enter the title and go to the next field, then, we load Google Translate service into our script, call translate function to translate from “fa” (Persian) to “en” (English) and finally clean the result using our old trick. That’s all and no magic here!

Please note that we show and hide a “Loading” element (e.g.: a loading image) before and after we call AJAX translate function. So user can see something is happening behind the scene.

 
 

kick it on DotNetKicks.com


 
Categories: AJAX | i18n | JavaScript | SEO | Tips and Tricks

Once again I want to talk about URLs and who doesn’t know that I’m a big fan of friendly, clean and pretty URLs in my applications! When you write an application (for example a blog engine) you have multiple choices to create unique URL for a single post; you can include an integer ID (myblog.com/458) or a GUID instead of integer or the best way, a friendly URL like myblog.com/hey-i-am-a-clean-url. This value should be unique and should not be changed if your blog post title is changed; so we should have a separate column in our database table to store this friendly URL. I wrote a simple JavaScript code that receives your blog post title, clean it from non alphanumeric characters and replaces them with a dash, change all characters to lower case and make it ready to be sent to your business logic handler:

<script type="text/javascript" language="javascript">
    function parseUrl(url) {
        var cleanUrl = (url + " ").replace(/[^a-zA-Z0-9]+/g, "-");
        return cleanUrl.slice(0, cleanUrl.length -1).toLowerCase();
</script>

and this two lines of code to fill URL field automatically as user types the post title (using jQuery:

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $("#postTitle").keyup(function() { $("#postUrl").val(parseUrl($("#postTitle").val())) }
        );
    });
</script>

 

This is very useful if you’re building applications using ASP.NET MVC and have control over URLs using routing engine. This is also helpful for WebForms developers who use routing in WebForms or rewrite extension less URLs using IIS7, ISAPI_REWRITE and etc.

Let your URLs be more friendly against search engines ;)

kick it on DotNetKicks.com


 
Categories: ASP.NET | ASP.NET MVC | JavaScript | SEO | Tutorial

If you live in Iran and are MCI carrier subscriber and also you have an iPhone, you might ask yourself how to enable voicemail on your iPhone. I give you some quick steps to enable voicemail on your iPhone:

  1. Click on Phone icon and then Keypad and dial *5005*86*09912#
  2. Press call and wait.
  3. Now you can access your voicemail box by tapping Voicemail in Phone.
  4. To enable forwarding calls in various situations go to step 1 and dial these commands instead:
    • Forwarding all calls to voicemail: *21*09912#
    • Forwarding calls when your phone is busy: *67*09912#
    • Forwarding calls when no reply from you: *61*09912#
    • Forwarding calls when your phone is unreachable: *62*09912#

 

Please note that voicemail service should have been already activated on your account. It’s not activated by default when you purchase your SIM Card.


 
Categories: iPhone | Tips and Tricks | Tutorial

Right after Apple upgraded its iPhone OS to v.3.0 and introduced new Push Notification feature many companies and developers started to write new applications or update their existing apps to use this new cool feature. One of them was BNO News which sends out breaking news alerts in four different ways: 1- Twitter, 2- Email, 3- Friendfeed, 4- iPhone. First three services are free but the last one is not free. You have to pay for their application as well as a monthly subscription fee to receive alerts on your iPhone. I was thinking to find a way to receive these alerts for free and I find a tricky way that I want to share with you here. You have to follow these steps to enable BNO alerts on your iPhone without paying them a penny!

  1. Download and install TextFree Lite on your iPhone. It’s free.
  2. Create a TextFree account which gives you a unique @textfree.us email address to receive messages.
  3. Create a new GMail account at http://mail.google.com/mail/signup
  4. Go to BNO mail subscription page and subscribe using your new GMail address.
  5. Login to your new GMail account and wait until BNO confirms your subscription then go to GMail Settings > Forwarding and POP/IMAP

    GmailSettings
    GmailForwarding 

    Now put your textfree.us email address in the text box labeled with “email address” (see above) and save your settings.
  6. You’re done! Each time BNO sends an alert to your GMail address it is automatically forwarded to your textfree.us and therefore you receive a Push Notification alert on your iPhone!

 

Do you know why we used GMail account in the middle of our trick and didn’t use textfree.us address directly? BNO rejects subscription requests from all @textfree.us or similar services email addresses!

Hope you enjoy this trick ;)


 
Categories: Download | iPhone | News | Tips and Tricks | Tutorial

One of the most amazing features of ASP.NET MVC is its powerful routing engine that let you define clear URLs for your web application. Today I want to share a very simple and short tip with you to handle non-English URLs in your ActionLink methods.

Let’s start with an example; in a blog engine we have two routes as follows:

routes.MapRoute(
                "ShowPost",
                "read/{url}",
                new { controller = "Post", action = "Show" }
            );
 
routes.MapRoute(
                "EditPost",
                "edit/{url}",
                new { controller = "Post", action = "Edit" }
            );

and you decide to show a Persian title in a URL as follows: /blog/read/این-یک-عنوان-است

Everything is fine till now but if you want to put an ActionLink in your view to redirect user to edit page in this way:

<%= Html.ActionLink("Edit", "Edit", new { url = Model.Url }) %>

You will be redirected to an ugly encoded URL like this /edit/%D8%AA%D8%B3%D8%AA instead of /blog/edit/این-یک-عنوان-است

Here’s the simple trick to overcome this:

<%= HttpUtility.UrlDecode(Html.ActionLink("Edit", "Edit", new { url = Model.Url })) %>

That’s it!

kick it on DotNetKicks.com Shout it


 
Categories: ASP.NET MVC | i18n | Web Development

April 20, 2009
@ 11:13 AM

It's about one month that ScottGu and his team have released ASP.NET MVC 1.0 but still there aren’t numerous books on this topic available in the market. As I know by far, these titles are available to purchase: ASP.NET MVC Framework Preview and ASP.NET MVC 1.0 Quickly. I know there are many articles and blog posts containing valuable information and tutorials to start learning ASP.NET MVC but many developers prefer to read books because they are better structured to learn something. From the earlier previews, authors that had been starting to write books on this topic offered some sample chapters to introduce them to the community (and they are still doing) so I decided to list all (or at least most) of them here for a quick access. My list contains both PDF sample chapters as well as link to some authors’ blog posts which contain draft unedited versions of their books:

As Wrox has announced, Professional ASP.NET MVC 1.0 is to be published in April and we’re close to see what ASP.NET team have done as a book for ASP.NET MVC developers!

kick it on DotNetKicks.com Shout it


 
Categories: ASP.NET MVC | Book Review | Download | eBooks | Freebies

A few days ago I had a chance to see a tweet from Wrox inviting users to participate in a private review access to ASP.NET MVC 1.0 Website Programming: Problem - Design – Solution and fortunately I was among those 10 lucky guys who  gained access to the first eight chapters of the book (it sounds good that authors are starting to offer sample chapters in private or public preview forms like what ScottGu has done by publishing the first chapter of Professional ASP.NET MVC 1.0). Meanwhile I don’t want to write a classic review post about this book because the book is not yet officially published and also I don’t have access to other chapters. I just want to thank Wrox guys and book authors to do this and I’m sure such movements will increase Wrox books quality.

What I want to talk about in this blog post is a very good ‘How to’ section in chapter 2 of this book: ‘How do I choose between MVC and Web Forms’. It has been a common question among all ASP.NET developers since the first preview releases of ASP.NET MVC and many guys in the community have wrote posts and articles about it. The last discussion I remember on this topic was Rachel Appel’s session at MIX ‘09 titled ‘Choosing between ASP.NET Web Forms and MVC’ (you can also download a high-res video here) that was very useful. After reading the book preview chapters I found a very good and practical way to rank your real need in the book and it was a worksheet to help you make the right decision for a project; as we read in the book:

After publishing this post I found out that author has already posted about this on his own website. So to respect his and Wrox Press rights I removed the mentioned section from chapter 2 of the book and you can read about it at http://www.coderjournal.com/2008/12/introducing-aspnet-mvc-part-2-aspnet-mvc-vs-webforms/ 


P.S.: I want to thank Nick Berardi, Al Katawazi and Marco Bellinaso, that are the book authors, for their cool book :-)

P.S. (2): As I found out (after publishing this post, and I swear I haven’t ever seen that) there is an original post about this by Nick Berardi and so I reference it here and I may remove the whole post content except this link if Nick or Wrox request (I did it) that but it seems that someone likes to argue about this more than what the owners of the book should do. Dear Lee! I don’t need to get impression as you said; I just wanted to spread a good word and thank them but you introduced me as a community killer and I’m so sorry for you!

kick it on DotNetKicks.com


 
Categories: ASP.NET | ASP.NET MVC | Book Review

A few months ago I found an amazing Web 2.0 free service called Chi.mp. As Chi.mp guys have stated in their about section, main goal of this service is centralizing online identity consists of content (blog entries, photos, videos, tweets, etc.) and your contacts and friends in one place. Once you sign up with them you receive a dedicated domain name with .mp extension (.mp is the ccTLD for the U.S. Commonwealth of the Northern Marianas Islands (CNMI); for more information take a look at get.mp website) and then you can setup and configure your current social activities into your domain.mp. Many services like Twitter, Flickr, YouTube, Facebook, RSS Feeds, etc. are supported now. Your visitors then can see your latest updates on social sites in one place and also can see your contact information based on your public/private settings.

Another amazing feature that Chi.mp offers to its users is OpenID! Yes! Chi.mp is an OpenID provider and once you sign up with them, your own domain name is an OpenID address as well. This is great because you can use a very pretty, short and easy to remember address as your OpenID instead of those ugly URLs provided by Google, Yahoo and other OpenID service providers!

You can also define an email address on your own .mp domain name and forward it to your favorite email address. Mine is i@mahdi.mp now!

Chi.mp is a ‘by invites only’ service at present and you should request current .mp owners to send you an invite (if any left!) or being in a waiting list by adding your information here. [Sorry! I don’t have any invites at present!]

Since Chi.mp is still in beta stage there are many many features that can be added and more enhancements that can be applied to this service and I’m sure it can be one of the most favorite services of 2009 among Web 2.0 geeks.

By the way, my Chi.mp account can be found at http://mahdi.mp ;-)


 
Categories: Freebies | Personal | Web 2.0