Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:02:18+00:00 2026-06-18T09:02:18+00:00

I know there are a few questions out there on this already but none

  • 0

I know there are a few questions out there on this already but none seem to help my problem.

I am debugging a VB.NET webForms app and I cannot Get FormsAuthentication.SetAuthCookie to work (with a non-persistent cookie). It seems to create an HttpContext.Current.User object when I check for it in a watch window it seems to have created the object, but not its “Identity” property.

I’ve read a bunch of SO posts checked the basic things, like seeing if my browser supports cookies, etc… This project is a direct port from an earlier project of ours, which uses the same code for all things listed here, and it works just fine, relatively speaking. Where this throws an exception is where it’s called from my BLL code that is supposed to get it.

Here is the code that calls the FormsAuthentication method…:

    'When participant logs in having already created records in DB. 
Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnGo.Click
    If Me.txtUsername.Text.Trim.Length <> 0 AndAlso Me.txtPassword.Text.Trim.Length <> 0 Then
        If Membership.ValidateUser(Me.txtUsername.Text, Me.txtPassword.Text) Then
            FormsAuthentication.SetAuthCookie(Me.txtUsername.Text, False)

            'This is where we run into trouble; the property checks with the forms auth...
            MyBLL.Common.CurrentUser = New MyBLL.User(Me.txtUsername.Text)

            'set site property.. 
            If Site_ IsNot Nothing Then
                MyBLL.Common.CurrentUser.Site = Me.Site_
            End If
            MyBLL.Common.CurrentParticpant = Nothing
            MyBLL.Common.CurrentParticpantVisitID = -1
            Response.Redirect("~/Apps/Dashboard.aspx", True)
        Else
            Me.lblLoginMsg.Visible = True
        End If
    Else
        Me.lblLoginMsg.Visible = True
    End If
End Sub

Here is the code for the BLL object (which has a shared property calling user from HttpContext…)

        Public Shared Property CurrentUser() As MyBLL.User
        Get
            Dim objUser As MyBLL.User

            If Not IsNothing(HttpContext.Current.Session("currentSiteUser")) Then
                objUser = CType(HttpContext.Current.Session("currentSiteUser"), MyBLL.User)
                If objUser.Username <> HttpContext.Current.User.Identity.Name Then
                    objUser = New MyBLL.User(HttpContext.Current.User.Identity.Name)
                    HttpContext.Current.Session("currentSiteUser") = objUser
                End If
            Else
                objUser = New MyBLL.User(HttpContext.Current.User.Identity.Name)
                HttpContext.Current.Session("currentSiteUser") = objUser
            End If

            Return objUser

        End Get
        Set(ByVal value As MyBLL.User)
            '_CurrentUser = value
            HttpContext.Current.Session("currentSiteUser") = value
        End Set
    End Property

Here is the Forms element from my webConfig; everything seems alright here to me…

    <authentication mode="Forms">
        <forms loginUrl="~/Public/Default2.aspx" defaultUrl="~/Public/Default2.aspx" timeout="60"/>
    </authentication>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:02:20+00:00Added an answer on June 18, 2026 at 9:02 am

    You should immediately redirect after callaing the SetAuthCookie method and only on subsequent requests you may hope to get the full IPrincipal to be initialized. Do not try to access HttpContext.Current.User.Identity.Name in the same controller action in which you called the SetAuthCookie method. It won’t have any effect. The redirect is important so that on the next request the forms authentication module will built the principal from the request cookie.

    In your CurrentUser method you seem to be calling the HttpContext.Current.User.Identity.Name property but this is not available until you redirect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are already a few questions like this but I can't seem
I know there are a few questions on stack already regarding this, and I
there are already a few questions relating to this problem. I think my question
Disclaimer: I know there are quite a few questions out there with this topic
There were few questions related to this but none answered the question in my
I know that there are a quite a few questions on this out there
So I know there is a few templating engines out there, but I thought
Hey I know there are already a few posts about this - yet I
I know there are plenty of questions here already about this topic (I've read
I know there are a lot of questions out there about this - believe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.