views:

37

answers:

1

I'm using DotNetOpenAuth as my membership system, and the way I have it working now seems to be working quite well. What I'd like to do however is build into my website the ability to check user credentials against the AuthCookie rather than a session.

In the membership provider, I can check for the username like this

    string UserName = System.Web.HttpContext.Current.User.Identity.Name; 
    ''# which returns the OpenId ClaimedIdentifier

What I'm wondering is if there is a way to extend this so that I can retrieve custom properties from the AuthCookie rather than having to create my own session object.


Currently I have this setup.

UserSessionModal

Namespace Domain
    Public Class UserSessionModel
        Public Property ID As Integer
        Public Property RegionID As Integer
        Public Property Username As String
        Public Property Slug As String
        Public Sub New(ByVal user As User)
            _ID = user.ID
            _RegionID = user.RegionID
            _Username = user.UserName
            _Slug = Replace(user.UserName, " ", "-")
        End Sub
    End Class
End Namespace

BaseController (inherited by all controllers)

Protected Overrides Function CreateActionInvoker() As System.Web.Mvc.IActionInvoker

    ''# Create a UserInfo object for the logged in user
    ''# and store it in a session state.
    If Session("UserInfo") Is Nothing AndAlso User.Identity.IsAuthenticated Then

        Dim user As Domain.UserSessionModel = New Domain.UserSessionModel(OpenIdService.GetOpenId(HttpContext.User.Identity.Name).User)
        Session("UserInfo") = user
    End If

    Return MyBase.CreateActionInvoker()
End Function

Then in my views I do something like this

<%  
    Dim user As MyApp.Core.Domain.UserSessionModel = DirectCast(Session("UserInfo"), MyApp.Core.Domain.UserSessionModel)
%>
<%: Html.ActionLink(user.UserName, "Details", "Users", New With {.id = user.ID, .slug = user.Slug}, Nothing)%>

What I really need to be able to do is remove the Session stuff all together and just simply check the AuthCookie for my custom properties ID, RegionID, Username, and Slug.

I can already get the "ClaimedIdentifier" out of the AuthCookie using HttpContext.User.Identity.Name... I just need to be able to extend it.

Thanks in advance.

A: 

This question seems to be simply different expression of this question and my answer will be the same.

Cheers.

Sky Sanders