[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C#.net - issues wiht code

Posted on 2011-10-02
4
Medium Priority
?
173 Views
Last Modified: 2013-12-16
I am finding that the below has some syntax errors...
if (Session("sessionTest_user") == 3)
            {
                if (string.IsNullOrEmpty(Session("SessionUsername")) | string.IsNullOrEmpty(Session("sessionPassword")))
                {
                    Response.Redirect("~/client/sys_messages/Customer_Failed_User_Login.aspx");
                    return functionReturnValue;
                }
            }

Open in new window

0
Comment
Question by:GlobaLevel
  • 2
4 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 36901373
try using [] for accessing the session e.g. Session["item_index"]. If thats not it please post the error.
0
 
LVL 12

Accepted Solution

by:
viralypatel earned 2000 total points
ID: 36901379
The "OR" in your if statement should have two pipes i.e. ||
(You have just one as seen in the code)

if (Session("sessionTest_user") == 3)
            {
                if (string.IsNullOrEmpty(Session("SessionUsername")) || string.IsNullOrEmpty(Session("sessionPassword")))
                {
                    Response.Redirect("~/client/sys_messages/Customer_Failed_User_Login.aspx");
                    return functionReturnValue;
                }
       

Open in new window

    }
0
 
LVL 12

Expert Comment

by:viralypatel
ID: 36901392
Also, Error      1      'System.Web.UI.Page.Session' is a 'property' but is used like a 'method'      

use Session["SessionUsername"] and Session["sessionPassword"]
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36901456
Session("SessionUsername") the ( should be changed as []. I mean that should be as Session["SessionUsername"]. The or condition should be ||. Now it is mentioned as |. That is wrong.

Always typecast to integer while comparing with integer.

In Response.Redirect() method pass second parameter as false to avoid unwanted thread abort exception message.



if(Session["sessionTest_user"] != null)
{
if ( int.Parse(Session["sessionTest_user"]) == 3)
            {
                if (string.IsNullOrEmpty(Session["SessionUsername"]) || string.IsNullOrEmpty(Session["sessionPassword"]))
                {
                    Response.Redirect("~/client/sys_messages/Customer_Failed_User_Login.aspx", false);
                    return functionReturnValue;
                }
      }
}

Open in new window

0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question