Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

User Page Authentication Using Sessions

I am trying to prevent unauthorized access to pages on my VB.Net website. I have set up users manually and I am using Sessions to store the information about the User. I am not using the built in login and authentication features due to other reasons.

The code I am trying to run on Page Load is ..
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Role") = "Admin" Then

        Else
            Response.Redirect("Default.aspx")
        End If
    End Sub

Open in new window


So if the Session("Role") is "Admin" then it will do nothing and allow the user access to the page, but for all other users it will send them back to the homepage.

This however doesnt work, you always get sent back to the default.aspx page, regardless of whether Session("Role") = Admin or not, as I have checked by using a MsgBox(Session("Role")), which returns "Admin".

Im thinking im using the wrong event, should I use something instead of Load?

Cheers,

Chris
0
CHKillswitch
Asked:
CHKillswitch
  • 3
  • 2
1 Solution
 
mayank_joshiCommented:
where have you created Session("Role") ?
0
 
mayank_joshiCommented:
example for adding column:-

   
    DataGridViewColumn col = new DataGridViewColumn();
	DataGridViewCell cell = new DataGridViewTextBoxCell();
	col.CellTemplate = cell;
	col.HeaderText = "testing";
	col.Name = "testing";
	col.Visible = true;
	col.Width = 60;

Open in new window

0
 
Rahul AgarwalTeam LeaderCommented:
Please create the Session("Role")  in the login page or where ever required then only check it because the sessions are not created automatically.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
mayank_joshiCommented:
Sorry ignore my second post.It was meant to be for some other question.
0
 
CHKillswitchAuthor Commented:
I realised that the problem was the Session was being created with spaces after the string, which when i was comparing it to "Admin" was causing a problem, So i ran the Session("Role") through a function that removed white spaces and it works fine now.
0
 
CHKillswitchAuthor Commented:
Solved!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now