473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

User views and QueryString

63
HI, I am trying to redirect users to the appropriate page based on the company role stored in the database. I have written the following code, but it doesn't seem to work. If the role is anything other than 'Admin', companyuser.aspx should load. Also, I am trying to append the user ID and username to the URL. At the moment it is hardcoded. Does anyone know how to obtain this from the db? Thanks in advance for your help!

Expand|Select|Wrap|Line Numbers
  1. protected void btnLogin_Authenticate(object sender, EventArgs e)
  2.     {
  3.         SqlDataSource sds = new SqlDataSource();
  4.         sds.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnection"].ToString();
  5.  
  6.         sds.SelectParameters.Add("Email", TypeCode.String, this.login_username.Text);
  7.         sds.SelectParameters.Add("Password", TypeCode.String, this.login_password.Text);
  8.  
  9.         sds.SelectCommand = "SELECT * FROM Member WHERE [email] = @Email AND [Password] = @Password";
  10.  
  11.         DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);
  12.  
  13.         SqlConnection myConnection;
  14.         SqlCommand myCommand;
  15.         SqlDataReader myDataReader;
  16.  
  17.         myConnection = new SqlConnection(GetConnectionString());
  18.         myConnection.Open();
  19.  
  20.         //prepare sql statements
  21.         myCommand = new SqlCommand("SELECT * FROM Member", myConnection);
  22.         myDataReader = myCommand.ExecuteReader();
  23.  
  24.         if (dv.Count == 0)
  25.         {
  26.             Response.Redirect("~/loginattempt.aspx");
  27.         }
  28.         else
  29.         {
  30.             while (myDataReader.Read())
  31.             {
  32.                 string companyrole = myDataReader["CompanyRole"].ToString();
  33.                 if (companyrole.Equals("Admin"))
  34.                 {
  35.  
  36.                     int ID = 10;
  37.                     string name = "Admin";
  38.                     Response.Redirect("~/companyadmin.aspx?id=" + ID + "&name=" + name);
  39.  
  40.                 }
  41.                 else
  42.                 {
  43.                     int ID = 10;
  44.                     string name = "Developer";
  45.                     Response.Redirect("~/companyuser.aspx?id=" + ID + "&name=" + name);
  46.                 }
  47.             }
  48.         }
  49.  
  50.         //cleanup objects
  51.         myDataReader.Close();
  52.         myConnection.Close();
  53.     }
  54.  
Nov 21 '10 #1
2 1263
ThatThatGuy
449 Expert 256MB
What's the structure of your Member table.
It must be having fields like ID and Password.
So you can use the existing DataReader instance to get the id and password.
Expand|Select|Wrap|Line Numbers
  1.  string companyrole = myDataReader["CompanyRole"].ToString();
The way you're checking the Company Role...
Nov 21 '10 #2
MiziaQ
63
Thanks, I got the QueryString working. The only problem now is that I get redirected to the companyadmin page even if the company role is not 'Admin'. Do you know how I can fix that? Thanks!
Nov 21 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Deepiceman | last post by:
Hi all, I am new to asp so bear with me. I want to write a page which will load a default page for me with some links and all. lets say someone clicks on the link, which not only points to the...
3
by: Arpan | last post by:
A link has the following URL: <a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%= Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2") %>&cplace=<%=...
4
by: Max | last post by:
Hello. This is the first time I've posted to a newsgroup, and I do this because I'm in desperate need of help. I'm working a user management system, and when I activate a user that has registered...
0
by: Samuel Fung | last post by:
Hi all, Can ASP retrieve UTF-8 encoded data in query string properly, when used with IIS 5.0 on Windows 2000 Pro/Server? With some trial and error, it seems that adding the directive...
18
by: | last post by:
Please help. After a number of wrong turns and experiments I need advice on login management system to secure our web pages without inconveniencing our visitors or our internal staff. What I...
0
by: Lloyd Dobbler | last post by:
Hi, I'm not that up on SQL as a whole as I've concentrated mainly on frontend and most of the DB backend work I've done has been with "Access" as that's all the site needed. I have however...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
1
by: Neil Chambers | last post by:
I currently have 2 databases with one website per DB. The databases are simple collections of views and some tables holding keys for the views - these DBs are exact copies of eachother, other than...
6
by: Cirene | last post by:
I have a subdir called "customer" that only allows authenticated users (using web.config.) In my login.aspx I allow them to pass username/password in query string. Then I go to a default page. ...
0
by: deepant | last post by:
Hi, I am writing a windows application in C#.net for watching a folder using filesystemwatcher class with this class i can able to track the events of creating,deleteing,changing and renaming...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.