Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
October 2008 - Posts - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

October 2008 - Posts

ASP.NET Podcast Show #125 - Routing with Webforms

Subscribe to All!

Subscribe to WMV.

Subscribe to M4V (iPod).

Subscribe to MP3.

Download WMV.

Download M4V (iPod).

Download MP3.

Show Notes:

  • Not just for MVC.
  • Available with .NET 3.5 SP1.
  • System.Web.Routing.
  • Web.config.
  • Global.asax.
  • Routing class.
  • Security.
  • Output page.

Source Code:

Web.config entry:

<httpModules>
.......
<add name="Routing" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

Global.asax:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;

.................

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            string strUrlPat = String.Empty;
            Route rteRoute, rte2;

            strUrlPat = "{controller}/{action}/{nameid}";

            rteRoute = new System.Web.Routing.Route(strUrlPat, new DisplayHandler());
            System.Web.Routing.RouteTable.Routes.Add(rteRoute);

            strUrlPat = "Book/{ISBNid}";
            rte2 = new Route(strUrlPat, new BookHandler());
            RouteTable.Routes.Add(rte2);

        }

Handler class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Web;
using System.Web.Compilation;
using System.Web.Routing;
using System.Web.Security;
using System.Web.UI;

namespace WAP
{
    public class DisplayHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext rc)
        {
            var routingPage = __LongTerm__ typeof(Page));
            routingPage.ControllerValue = rc.RouteData.Values["controller"] as string;
            routingPage.ActionValue = rc.RouteData.Values["action"] as string;
            routingPage.ProductValue = rc.RouteData.Values["nameid"] as string;
            return (routingPage);
        }
    }

    public class BookHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext rc)
        {
            string VirtualPath = "~/Routing/Books.aspx";
            if (!UrlAuthorizationModule.CheckUrlAccessForPrincipal(VirtualPath,
                rc.HttpContext.User,
                rc.HttpContext.Request.HttpMethod))
                throw (new SecurityException());
            var routingPage = (WAP.Routing.Books)BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page));
            routingPage.ISBNNumber = rc.RouteData.Values["ISBNid"] as string;
            return (routingPage);
        }
    }
}

Codebehind page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WAP.Routing
{
    public partial class RoutingExample : System.Web.UI.Page
    {
        public string ControllerValue { get; set; }
        public string ActionValue { get; set; }
        public string ProductValue { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                lblController.Text = ControllerValue;
                lblAction.Text = ActionValue;
                lblProduct.Text = ProductValue;
            }
        }
    }
}

ASP.NET Podcast Show #124 - Speed up big Apps with Velocity!

Subscribe

Subscribe to the MP3 Only Feed

Download

Show Notes:

ASP.NET Podcast Show #123 - Community Discussion at CodeStock

Original Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/08/20/asp-net-podcast-show-123-community-discussion-at-codestock.aspx

Subscribe to Everything.

Subscribe to WMV format.

Subscribe to M4V for iPod Users.

Subscribe to MP3 (Audio only).

Remember, subscribing is good for the soul.

Download WMV.

Download M4V for iPod Users.

Download MP3 (Audio only).

Show Notes:

ASP.NET Podcast Show #122 - CodeStock OpenSpaces Discussion regarding ORM

Original url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/08/15/asp-net-podcast-show-122-codestock-openspaces-discussion-regarding-orm.aspx

Subscribe to Everything.

Subscribe to WMV format.

Subscribe to M4V for iPod Users.

Subscribe to MP3 (Audio only).

Download WMV (Video format).

Download M4V for iPod Users.

Download MP3 (Audio Only).

Show Notes:

 

More Posts