none
Session Variable To String RRS feed

  • Question

  • I'm not sure why this is giving me an error:

    code:

    if (!string.IsNullOrEmpty(Config.Session["IntendedURL"].ToString())) szRedirectURL = Config.Session["IntendedURL"].ToString();

    

    Monday, April 1, 2019 6:19 PM

Answers

  • so this:

     if (Config.Session["IntendedURL"] != null) szRedirectURL = Config.Session["IntendedURL"].ToString();

    • Marked as answer by old_School Monday, April 1, 2019 7:26 PM
    Monday, April 1, 2019 6:35 PM

All replies

  • I don't think you want the .ToString() inside the 'if' statement.  Config.Session(...) is probably returning null.
    Monday, April 1, 2019 6:28 PM
  • so this:

     if (Config.Session["IntendedURL"] != null) szRedirectURL = Config.Session["IntendedURL"].ToString();

    • Marked as answer by old_School Monday, April 1, 2019 7:26 PM
    Monday, April 1, 2019 6:35 PM
  • First do a if statement to see if the item is null, if not null check if it's an empty string using a second if statement.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, April 1, 2019 6:42 PM
    Moderator