Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to access 'name' given when user registers

How to access 'name' given when user registers

Scheduled Pinned Locked Moved ASP.NET
databasetutorialquestionlearning
2 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    So I only want the logged in user to be allowed to book holidays for them selves. I think the easiest way to do this is to compare 'name' of logged in user againast 'name' in person table. So....

    public ActionResult Create()
    {
    string xx = (string)Session["usernameID"];
    int? currentPersonID = Convert.ToInt32(xx);

            string userNameComparedAgainstLoginName = // here is where i want to say 'name' of logged in user
    
            CreateModel model = new CreateModel();
            model.currentPersonID = currentPersonID.Value;
            model.PList4DD = db.People.ToList();   
           
    
            if (userNameComparedAgainstLoginName == model.userName)
            {
                ViewBag.Id = new SelectList(db.People, "Id", "Name");
                return View(model);
            }
            else
            {
                TempData\["canOnlyBookHolidaysForYourself"\] = "I'm afraid you can only book holidays for yourself";
                return RedirectToAction("Index");
            }
        } 
    

    --------------------------------------- the name given when the user registers will be the same names used in the db. So could someone tell me how I can access the logged in 'name'? Thanks

    X 1 Reply Last reply
    0
    • X xnaLearner

      So I only want the logged in user to be allowed to book holidays for them selves. I think the easiest way to do this is to compare 'name' of logged in user againast 'name' in person table. So....

      public ActionResult Create()
      {
      string xx = (string)Session["usernameID"];
      int? currentPersonID = Convert.ToInt32(xx);

              string userNameComparedAgainstLoginName = // here is where i want to say 'name' of logged in user
      
              CreateModel model = new CreateModel();
              model.currentPersonID = currentPersonID.Value;
              model.PList4DD = db.People.ToList();   
             
      
              if (userNameComparedAgainstLoginName == model.userName)
              {
                  ViewBag.Id = new SelectList(db.People, "Id", "Name");
                  return View(model);
              }
              else
              {
                  TempData\["canOnlyBookHolidaysForYourself"\] = "I'm afraid you can only book holidays for yourself";
                  return RedirectToAction("Index");
              }
          } 
      

      --------------------------------------- the name given when the user registers will be the same names used in the db. So could someone tell me how I can access the logged in 'name'? Thanks

      X Offline
      X Offline
      xnaLearner
      wrote on last edited by
      #2

      forgot to mention Its just the automatic login that comes with mvc3 razor

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups