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. Users and Cookies in ASP.NET MVC

Users and Cookies in ASP.NET MVC

Scheduled Pinned Locked Moved ASP.NET
asp-netcsharpdatabasearchitecturehelp
4 Posts 3 Posters 0 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.
  • Q Offline
    Q Offline
    Quake2Player
    wrote on last edited by
    #1

    Hi, The situation is this: I would like to have an static method in some class of the Models library like this static User GetCurrentUser() Which takes a cookie in the user ("currentUserId") and returns the User retrieved from the db.. The problem: I cant have access to the cookies (to the "Request" class) from the Model lib. So what other solution can I use? Should I make that method in the Controllers library? IF i dont add a view to a method of a controller class then that method wont be an action? ALSO: The method needs to be used from other controllers.. so.. is that possible?

    A N 2 Replies Last reply
    0
    • Q Quake2Player

      Hi, The situation is this: I would like to have an static method in some class of the Models library like this static User GetCurrentUser() Which takes a cookie in the user ("currentUserId") and returns the User retrieved from the db.. The problem: I cant have access to the cookies (to the "Request" class) from the Model lib. So what other solution can I use? Should I make that method in the Controllers library? IF i dont add a view to a method of a controller class then that method wont be an action? ALSO: The method needs to be used from other controllers.. so.. is that possible?

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Why dont you use Static Property... HttpContext.Current.Request.Cookies This will do the trick... :rose:

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      N 1 Reply Last reply
      0
      • Q Quake2Player

        Hi, The situation is this: I would like to have an static method in some class of the Models library like this static User GetCurrentUser() Which takes a cookie in the user ("currentUserId") and returns the User retrieved from the db.. The problem: I cant have access to the cookies (to the "Request" class) from the Model lib. So what other solution can I use? Should I make that method in the Controllers library? IF i dont add a view to a method of a controller class then that method wont be an action? ALSO: The method needs to be used from other controllers.. so.. is that possible?

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Separation of concerns is a reason to use the MVC pattern. By trying to use the Request object in your model you are violating the tenets of MVC. There is not a one-to-one correlation between views and actions. You can have an action that redirects to another view or renders another view. Create a BL class that has the GetCurrentUser method and call it from the controllers as necessary.


        only two letters away from being an asset

        1 Reply Last reply
        0
        • A Abhishek Sur

          Why dont you use Static Property... HttpContext.Current.Request.Cookies This will do the trick... :rose:

          Abhishek Sur


          My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

          **Don't forget to click "Good Answer" if you like to.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          As a basic tenet of the MVC pattern the model should not need to know about such things.


          only two letters away from being an asset

          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