Tuesday 28 December 2010

URL Manipulation in IIS7

Following to my earlier post – on URL Manipulation

For IIS 7 – Can use URL Rewrite Rule -

<rewrite>
  <rules>
    <rule name="HtmlRewrite">
      <match url="(.*)(\.\w+)$" />
      <action type="Rewrite" url="{R:1}" />
    </rule>
  </rules>
</rewrite>

Refer IIS URL rewriting

 "Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination." -- Albert Einstein

Monday 27 December 2010

URL Manipulation with RouteBase

2] For URL manipulation  that should ignore the very end extension in url. the extension can be: .html, .aspx, .php

/Home.html should go to Home Controller and 
/Home/index.aspx should go to Home Controller Index Action.

Implement Custom Base entry RouteBase

public class MyUrlRoute : RouteBase
{

    public override RouteData GetRouteData(HttpContextBase httpContext)
    {
        //~/Account/LogOn
        //~/Home.aspx - Works fine
        //~/home/index.aspx  -Works Fine
        //http://localhost:57282/home/index/1/2/3 - Works fine
        //http://localhost:57282/Account/Register  http://localhost:57282/Account/LogOn - Works Fine

        string url = httpContext.Request.AppRelativeCurrentExecutionFilePath;

        //check null for URL
        const string defaultcontrollername  = "Home";
        string[] spliturl = url.Split("//".ToCharArray());
        string controllername = String.Empty;
        string actionname = "Index";



        if (spliturl.Length == 2) //for ~/home.aspx and ~/
        {
            if (String.IsNullOrEmpty(spliturl[1])) //TODO:  http://localhost:57282/ not working - to make it working
            {
                controllername = defaultcontrollername;
            }
            else
            {
                controllername = spliturl[1];
                if (controllername.Contains("."))
                {
                    controllername = controllername.Substring(0, controllername.LastIndexOf("."));
                }
            }
        }
        else if (spliturl.Length == 3) // For #/home/index.aspx and /home/about
        {
            controllername = spliturl[1];
            actionname = spliturl[2];
            if (actionname.Contains("."))
            {
                actionname = actionname.Substring(0, actionname.LastIndexOf("."));
            }
        }
        else //final block in final case sned it to Home Controller
        {
            controllername = defaultcontrollername;
        }


        RouteData rd = new RouteData(this, new MvcRouteHandler());
        rd.Values.Add("controller", controllername);
        rd.Values.Add("action", actionname);
        rd.Values.Add("url", url);
        return rd;
    }

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    {
        return null;
    }
and in global.aspx add below code.
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.Add(new MyUrlRoute()); // Add before your default Routes

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

Refer SO question


References. :

    // Implementing Custom Base entry - Pro Asp.Net MVc Framework       
    //- http://books.google.com/books?id=tD3FfFcnJxYC&amp;pg=PA251&amp;lpg=PA251&amp;dq=.net+RouteBase&amp;source=bl&amp;ots=IQhFwmGOVw&amp;sig=0TgcFFgWyFRVpXgfGY1dIUc0VX4&amp;hl=en&amp;ei=z61UTMKwF4aWsgPHs7XbAg&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=6&amp;ved=0CC4Q6AEwBQ#v=onepage&amp;q=.net%20RouteBase&amp;f=false      
    // phil haack's Route Debugger http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

Sunday 26 December 2010

URL Routing default.aspx ASP.NET MVC

1] In case if  Default.aspx need to be a start up page for  MVC project then 

Add  a new WebForm as a Default.aspx in Root directory ,

set it as Start up page

and on Page Load redirect it to your default URL. -

public partial class _default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Redirect("~/Home");
    }
}

 

Monday 13 September 2010

Hello F#


In this series we will take a walk into F# World. F# is a new functional programming language, targeting the .NET Framework.

Functional programming seems to be a buzz world for Multiprocessor programming and In my personal opinion think it is going to be more useful as we move more to Cloud computing in order to target muli processor computation power.

We will cover Why we need to use F# (functional language) in coming post. In mean time you can Google it with Bing.

In this series we will see how to get started with F#

1] Prerequisite - Visual Studio Web Developer 2010 Express.
You can download VS2010 web developer from MSDN site Free from
here.

2] Don’t forget to register your VS Web Express edition with Microsoft. Follow below steps
Registration.

3] Download F# -
Download links from Here.

a] VSIntShell.exe
b] InstallFSharp.msi

4] Once download is complete.
You can access F# Interactive (console) from menu Microsoft F# CTP 2.0.0.0.

And here we go- Our First F# Hello World Programme.


Please let me know your thoughts, suggestions.

Namskar

Saturday 11 September 2010

First Post

This is my very first blog and I am truly excited…honestly little bit nervous. This is something I've wanted to do for a long time, but wasn't sure How ,Why, Where, What to do it?

Before we proceed further let me introduce myself. Who am I?
I am currently working as a Software Developer on Microsoft Platform. I am eager to explore new technologies, productivity tools for faster development ,TDD development, etc.
Currently exploring my knowledge on MVC,SPARK view engine, jQuery,WPF,Windows phone 7and F#.

I am also doing study on Achievements of Ancient Indian Civilisation, benefits of Ayuerveda, Yoga and Meditiatation.

Why I am here?
Scott Hanselman - has a very good Video video
on technical blogging. Please visit it. And i wanted to do ot for a long time so I am here..

What?
I will be posting my views, problems i have solved, Solution Source code ,Links for other interesting Pod casts, Videos. Etc.
I will try to publish 1 or 2 posts for every month.

So see you soon again.

Namskar