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 8199059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:05:41+00:00 2026-06-07T06:05:41+00:00

I have the Guid UserID , it needs to be filled with Session(UserID) which

  • 0

I have the Guid “UserID” , it needs to be filled with Session(“UserID”) which is a String , but formatted to convert perfectly to a Guid.

If I try this , “Cannot Convert type string into type Guid”

       Dim UserID As New Guid()
       If HttpContext.Current.Session("UserID") IsNot Nothing Then
          UserID = HttpContext.Current.Session("UserID")
       End If

If I try this “Cannot Cast type string into type Guid”

       Dim UserID As New Guid()
       If HttpContext.Current.Session("UserID") IsNot Nothing Then
          UserID = DirectCast(HttpContext.Current.Session("UserID"), Guid)
       End If

This converts the string into Guid perfectly , but it is not accessable outside of the If Statement

       If HttpContext.Current.Session("UserID") IsNot Nothing Then
         Dim UserID As new Guid(HttpContext.Current.Session("UserID"))
       End If

I can not figure out how to define UserID outside of the If statement , then assign it conditionally

  • 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-07T06:05:42+00:00Added an answer on June 7, 2026 at 6:05 am

    Try with this

    Dim UserID As New Guid()
    If HttpContext.Current.Session("UserID") IsNot Nothing Then
        UserID = Guid.Parse(HttpContext.Current.Session("UserID").ToString())
    End If
    

    Just in case you’re confused, take into account that, unless my memory is failing, Guid contructor will generate an “empty” guid. If you want to generate a fresh guid use Guid.NewGuid()

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

Sidebar

Related Questions

I have this: namespace Demo.Framework.Domain { public class UserEntity { public virtual Guid UserId
I have these objects: public class Class { public Guid Id {get;set;} public string
I have a Datatable with Id(guid) and Name(string) columns. I traverse through the data
I feel like GUID/UUID questions have been done to death here, but I can't
I have a user object like so: public class User { public Guid UserId
Model: public class User { public Guid UserId { get; set; } public string
I have a GUID variable and I want to write inside a text file
Ok I have a GUID f5cc4100-f1b4-4af6-9e9e-224b0eb74166 and I am inserting it to MySQL database
I have two classes and mapping for the collection: class User { Guid ID;
I have a Dictionary<Guid, ElementViewModel> . (ElementViewModel is our own complex type.) I add

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.