Click here to Skip to main content
15,886,817 members
Articles / Web Development / ASP.NET

AsyncMethods - An Improvement on Microsoft's ScriptMethods

Rate me:
Please Sign up or sign in to vote.
4.76/5 (9 votes)
10 Aug 2011CPOL11 min read 29K   362   17  
A lightweight, secure, and better organized version of Microsoft's ScriptMethods.
Imports System.Xml.XPath
Imports Microsoft.VisualBasic

Public Class SiteUser
    Private MyIsLoggedIn As Boolean = False
    Public ReadOnly Property IsLoggedIn() As Boolean
        Get
            Return MyIsLoggedIn
        End Get
    End Property

    Private MyUserType As UserType = UserType.Anonymous
    Public ReadOnly Property UserType() As UserType
        Get
            Return MyUserType
        End Get
    End Property

    Private MyUserName As String = ""
    Public ReadOnly Property UserName() As String
        Get
            Return MyUserName
        End Get
    End Property

    Public Sub New(ByVal context As HttpContext)
        If context.User.Identity.IsAuthenticated Then
            MyIsLoggedIn = True
            MyUserName = context.User.Identity.Name

            Dim db As New Database()

            Dim el As XElement = db.Data.XPathSelectElement("Users/User[@Name='" & UserName & "']")

            If el Is Nothing Then Throw New Exception("Invalid User!")

            MyUserType = [Enum].Parse(GetType(UserType), el.@Role)
        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) digifi inc.
Canada Canada
Clayton Rumley is web developer for hire from Winnipeg, Manitoba, Canada.

Comments and Discussions