Why I'm Loving the ASP.NET MVC Framework

by elbandit 10. July 2009 06:10

As a lot of my work is done on the external web, I keep the code as simple as possible and try to use as few server controls as possible, this is why I am loving the MVC framework. Web forms were a great way to disguise the fact that the web is stateless and a great way for windows devs to get working on the web with relative ease and keep with their exisitng skills. The problem with web forms and the over use of complex server controls was that they abstracted away the raw html from the developer, MVC is giving this power back.

Before MVC I had starting to opt to leave out using server controls and instead went back to a classic-ish asp way of doing things with in line scripting, Rob Conery has a great post on this topic with lots of good debat that you should check out.

By the way there is a great chapter on MVC in my upcoming book Professional Enterprise .net.

kick it on DotNetKicks.com

Tags:

ASP.net | ASP.net MVC

Storing the UserID instead of the UserName in the User.Identity.Name Object when using the Login Control and ASP.net Membership API

by elbandit 5. June 2009 19:11

The problem I had wiith using the Membership API and the login Control was that by default after logging in the User.Identity.Name is set to the username that users logon with, and this is usually a string value i.e. their email address or username.

I wanted to store the user id in the User.Identity.Name varaible, this is how I achieved it using the Membership Login Control:

Imports System.Web.Security
Imports System.Web.UI.WebControls
Imports MySite.UserService

Partial Class MembersArea_CustomerLogin
    
Inherits System.Web.UI.Page                 

    Protected
Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs)  Handles Login1.LoggedIn
                    
              
Dim user As User
              ' The UserService is the interface into my business layer
              
Dim aUserService As New UserService
              ' This method simply returns the UserID of the user that has just been 
              ' logged in. We get the Username from the login control text box. 
              
user = aUserService.GetUserBy(Login1.UserName)
             
              ' Now that we have got the UserID we need to recreate the 
              ' authentication ticket we removed earlier otherwise
              ' the user will not be authenticated.
              
Dim authTicket As FormsAuthenticationTicket = _
                                   
New FormsAuthenticationTicket(user.Id , False , 30)              

             
Dim
encryptedTicket As String = FormsAuthentication.Encrypt(authTicket) 
              Dim authCookie As HttpCookie = _
                                  
New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)              
              HttpContext.Current.Response.Cookies.Add(authCookie)

      End Sub
End
Class

Now we can access the UserID where ever we want.

Dim productService As New ProductService
Dim allProjects As List(Of Projects)

allProjects = productService.GetAllProjectsBy(
CType(User.Identity.Name, Long))

Marvellous.

kick it on DotNetKicks.com

Tags:

ASP.net

Wrox Blox NHibernate with ASP.NET Problem–Design–Solution

by elbandit 5. June 2009 18:20

 

Back in March Wrox published an ebook that I wrote on getting started with NHibernate using ASP.net called NHibernate with ASP.NET Problem-Design-Solution but I didn't have a blog back then so I decided to blog about it now.

This is the low down:

"This Wrox Blox demonstrates how to start using NHibernate in line of business applications using ASP.NET and VB.NET. Using NHibernate will speed up your application development by removing the need to build your own Data Access Layer (DAL).  In addition, you can focus solely on the business problem instead of the infrastructure concerns. Using a simple demo application as an example, this Wrox Blox shows how easy it is to get started with NHibernate and build your DAL in minutes instead of hours. Readers will also see how the POCO pattern enables you to keep your DAL as unobtrusive as possible as well as being interchangeable for future DAL implementations. You will also see how NHibernate has many enterprise patterns built into it, like the Unit of Work pattern and the Identity Map."

It weights in at 123 pages and is available to download now for US $9.99. 

Table of Contents 

What Is an Object Relational Mapper? 2

Why NHibernate? 2

Part 1: Getting Started with NHibernate 2

A Quick Demo 2

Part 2: The NHibernate Framework 13

Architecture and Core Concepts 13

Mapping Your Entities: Impedance Mismatch 16

Persisting Business Objects 18

Part 3: Using NHibernate 19

Introducing the Project and Laying out the Solution Framework 19

Designing the Domain Model 23

NHibernate Repository Project: Base Class 39

Managing Products 48

Managing Customers 58

NHibernate Repository Project: Refactoring and Session Management 69

Managing Orders 74

The Database — A Question of Storage 94

Presentation with the Model–View–Presenter Pattern 96

User Interface: ASP.NET 103

Part 4: Other NHibernate Bits and Pieces 113

Other Querying Methods 113

Mapping Inheritance 115

What Kind of SQL Is Being Produced? 118

Wrap Up 119

You can get the download the Wrox Blox here NHibernate with ASP.NET Problem-Design-Solution.

The project to accompany the ebook is up on codeplex at http://www.codeplex.com/NHibernateASP.

kick it on DotNetKicks.com

Tags: ,

Books

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen