dcsimg
Results 1 to 2 of 2

Thread: Single Sign On Error - Could not find email

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2014
    Location
    Sweden
    Posts
    1

    Single Sign On Error - Could not find email

    I've been trying to make this work for weeks so I'm turning here as a last resort. I have a SSO application that runs on IIS which works fine on my own office and several other customers but this one specific customer keep getting this error in image below. I know the following settings are required for this specific SSO to work: Windows Authentication with no Anonymous access, set browser security settings to login with logged in user's credentials. All this and more is exactly the way I have it at my own office.

    Now to the question. The exception says "Could not find email for [BjoJon001]/[Domain name\BjoJon001]". Shouldn't it be just [Domain name\BjoJon001]? Could something in their specific Active Directory be weird? I'm guessing this line is throwing the exception
    Code:
    If UserFound.GetDirectoryEntry().Properties.Item("mail").Value.ToString.Trim = "" Then
                    Throw New Exception("Hittade ingen E-postadress för användare")
                End If
    I'm attaching the code below the image and I would be grateful for any help or hints.

    Name:  FelMeddelandeSuddad.jpg
Views: 174
Size:  27.4 KB

    Code:
    Imports System.DirectoryServices
    
    Public Class SSOInit
        Inherits System.Web.UI.Page
    
    #Region " Web Form Designer Generated Code "
    
        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    
        End Sub
    
        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object
    
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub
    
    #End Region
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            bestinRedirect()
        End Sub
    
        Private Sub bestinRedirect()
            'Put user code to initialize the page here
            Dim url As String = Encryption.appConfig.getAppConfigs("URL")
            If IsNothing(url) Then Throw New System.Exception("No URL is defined")
    
            If Not Request.Cookies("SSO") Is Nothing Then
                Dim Cookie As HttpCookie = Request.Cookies("SSO")
    
                Dim encryotedEmail = Cookie.Values("Email")
    
                If Not encryotedEmail Is Nothing AndAlso Not String.IsNullOrEmpty(encryotedEmail) Then
                    Response.Redirect(url & Server.UrlEncode(encryotedEmail))
                End If
    
            Else
    
                Dim encryptedMail As String
                Dim userFullIdentity As String = User.Identity.Name
                Dim userName As String = String.Empty
    
                Try
                    userName = userFullIdentity.Split("\")(1)
                Catch ex As Exception
                    Response.Write("Cannot find name part from [" + userFullIdentity + "]")
                    Response.Write("<br/>")
                    Response.Write(ex.StackTrace)
                    Throw
                End Try
    
                Dim mailAddress As String = String.Empty
                Try
                    mailAddress = GetMailAddress(userName)
                Catch ex As Exception
                    Response.Write("Could not find email for [" + userName + "]")
                    Response.Write("<br/>")
                    Response.Write(ex.StackTrace)
                    Throw
                End Try
    
                Dim retrievedKey As String = String.Empty
                Try
                    retrievedKey = Encryption.appConfig.getAppConfigs("encKey")
                Catch ex As Exception
                    Response.Write("Could not get key encryption key, please validate web.config")
                    Response.Write("<br/>")
                    Response.Write(ex.StackTrace)
                    Throw
                End Try
    
    
                encryptedMail = Encryption.EncryptString256Bit(mailAddress, retrievedKey)
    
                Dim cookie As New HttpCookie("SSO")
                cookie.Values.Add("Email", encryptedMail)
                cookie.Expires = DateTime.MaxValue ' Never Expires
    
                Response.AppendCookie(cookie)
                Response.Redirect(url & Server.UrlEncode(cookie.Values("Email")))
            End If
        End Sub
        Public Function GetMailAddress(ByVal UserID As String) As String
            Dim RootDSE As New DirectoryEntry("LDAP://RootDSE")
    
            Dim DomainDN As String = String.Empty
    
            Try
                DomainDN = RootDSE.Properties("DefaultNamingContext").Value
            Catch ex As Exception
                Response.Write("Could not get act hold of the domain name")
                Response.Write(ex.StackTrace)
                Throw
            End Try
    
            Dim ADEntry As New DirectoryEntry("LDAP://" & DomainDN)
            Dim ADSearch As New DirectorySearcher(ADEntry)
            Dim ADSearchResult As System.DirectoryServices.SearchResult = Nothing
    
            ADSearch.PropertiesToLoad.Add("memberOf")
            ADSearch.Filter = ("(samAccountName=" & UserID & ")")
            ADSearch.SearchScope = SearchScope.Subtree
            Dim UserFound As SearchResult = ADSearch.FindOne()
            If Not IsNothing(UserFound) Then
                Dim propertyCount As Integer = UserFound.Properties("memberOf").Count
                If UserFound.GetDirectoryEntry().Properties.Item("mail").Value.ToString.Trim = "" Then
                    Throw New Exception("Hittade ingen E-postadress för användare")
                End If
            Else
                Throw New Exception("Hittade ingen användare")
            End If
    
            Try
                Return UserFound.GetDirectoryEntry().Properties.Item("mail").Value
            Catch ex As Exception
                Response.Write("Could not get a hold of user mail.")
                Response.Write(ex.StackTrace)
                Throw
            End Try
    
        End Function
    
    
    End Class

  2. #2
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Single Sign On Error - Could not find email

    Thread moved to the ASP.Net forum.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width