troubleshooting Question

C#.net Custom Control Login Check namespace

Avatar of j_tipps
j_tipps asked on
.NET Programming
25 Comments1 Solution632 ViewsLast Modified:
Hello,
I'm haveing a problem using a control class to verfify if someone is login and if not repsond correctly.
It can't seem to import the correct namespace for the User.Identity.IsAuthenticated.  
I'm using windows authentication.
I have read something about Page.User....no idea.

For now i have this code in regualer code behind files and it works fine.  I'm not trying to get all my reusable items together and since this is code would be in almost every page it was the first on my list :)

here is the code in the class that i'm haveing a namespace problem:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace VenderRisk
{

      public class Common
      {
            SqlConnection Conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            
            public Common()
            {
                  //
                  // TODO: Add constructor logic here
                  //
            }
            public bool CheckLog()
            {
                  DataTable UserTB = new DataTable();
                  bool HowAboutIt;
                  if ((User.Identity.IsAuthenticated) & (Request.Cookies["UserInfo"] != null))      
                  {
                        HowAboutIt = true;
                        return HowAboutIt;
                  }
                  else
                  {
                        
                        SqlCommand SelRoles = new SqlCommand("SELECT   Users.RecID, Users.NTLog, Users.Fname, Users.Lname, Users.Email, Users.Phone, Users.EmpID, Users.Role, LOB.LOBID FROM  Users INNER JOIN  LOB ON Users.LOB = LOB.LOBID WHERE  (NTLog = @ID)", Conn);
                        SqlParameter Userparam  = new SqlParameter();
                        Userparam.ParameterName = "@ID";
                        Userparam.Value = User.Identity.Name.ToString();
                        SelRoles.Parameters.Add(Userparam);
                        SqlDataAdapter  FillRoles = new SqlDataAdapter(SelRoles);
                        FillRoles.Fill(UserTB);
                        if (UserTB.Rows.Count > 0)
                        {
                              HttpCookie cook = new HttpCookie("UserInfo");
                              cook.Values.Add("UserRole",UserTB.Rows[0]["Role"].ToString());
                              cook.Values.Add("LOBID", UserTB.Rows[0]["LOBID"].ToString());
                              cook.Values.Add("UserID", UserTB.Rows[0]["RecID"].ToString());
                              cook.Expires = DateTime.Now + TimeSpan.FromDays(1);
                              Response.Cookies.Add(cook);
                        }
                        else
                        {
                              Response.Redirect("http://" + Request.ServerVariables["http_host"] + "/VenderRisk/AddUsers.aspx");
                        }
                  }
            }
      }
}

Whats going on?  why wont it work? it has the correct namespace and then some!
I'm also haveing a problem with Request and Response namespaces.
I think i'm just miss understanding something.
Thanks for any help.
ASKER CERTIFIED SOLUTION
sumo_the_cat

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 25 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 25 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros