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 give access to different user for different pages in asp.net with c#

how to give access to different user for different pages in asp.net with c#

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorial
8 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.
  • D Offline
    D Offline
    developerit
    wrote on last edited by
    #1

    how to give acess to different users for different pages (ie when user login based on his permissions he should be able to access his pages) usin asp.net with c#

    R P 2 Replies Last reply
    0
    • D developerit

      how to give acess to different users for different pages (ie when user login based on his permissions he should be able to access his pages) usin asp.net with c#

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      You could use an atrribute to check the status of the user and redirect accordingly. Here is some simplistic pseudo code:

      [AttributeUsage(AttributeTargets.All)]
      public sealed class UserStatus : Attribute
      {
      public UserStatus()
      {
      if (!UserShouldBeHere)
      {
      HttpContext.Current.Response.Redirect("SomewhereElse.aspx");
      }
      }
      }

      At the top of each page you want to check this on decorate the class with:

      [UserStatus]
      public partial class MyAccount : Page
      ... code continues

      me, me, me

      P 1 Reply Last reply
      0
      • R R Giskard Reventlov

        You could use an atrribute to check the status of the user and redirect accordingly. Here is some simplistic pseudo code:

        [AttributeUsage(AttributeTargets.All)]
        public sealed class UserStatus : Attribute
        {
        public UserStatus()
        {
        if (!UserShouldBeHere)
        {
        HttpContext.Current.Response.Redirect("SomewhereElse.aspx");
        }
        }
        }

        At the top of each page you want to check this on decorate the class with:

        [UserStatus]
        public partial class MyAccount : Page
        ... code continues

        me, me, me

        P Offline
        P Offline
        Palash Biswas
        wrote on last edited by
        #3

        Use.. [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] public partial class Test : System.Web.UI.Page Only the user palash of domain Kovairindia will access this page. If Other one say rahul of Kovairindia domain will get System.Security.SecurityException exception. N.B:You can also give a permission to a Role for your page.

        R 1 Reply Last reply
        0
        • P Palash Biswas

          Use.. [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] public partial class Test : System.Web.UI.Page Only the user palash of domain Kovairindia will access this page. If Other one say rahul of Kovairindia domain will get System.Security.SecurityException exception. N.B:You can also give a permission to a Role for your page.

          R Offline
          R Offline
          R Giskard Reventlov
          wrote on last edited by
          #4

          Thanks, but I know what I meant. You should add this as a separate answer as it is equally as valid and should be able to be marked on it's own. (Not everyone uses principals, roles, etc, to model security).

          me, me, me

          P 1 Reply Last reply
          0
          • D developerit

            how to give acess to different users for different pages (ie when user login based on his permissions he should be able to access his pages) usin asp.net with c#

            P Offline
            P Offline
            Palash Biswas
            wrote on last edited by
            #5

            Use.. [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] public partial class Test : System.Web.UI.Page Only the user palash of domain Kovairindia will access this page. If Other one say rahul of Kovairindia domain will get System.Security.SecurityException exception. N.B:You can also give a permission to a Role for your page.

            1 Reply Last reply
            0
            • R R Giskard Reventlov

              Thanks, but I know what I meant. You should add this as a separate answer as it is equally as valid and should be able to be marked on it's own. (Not everyone uses principals, roles, etc, to model security).

              me, me, me

              P Offline
              P Offline
              Palash Biswas
              wrote on last edited by
              #6

              Sorry some mistake was there i did not want to post the message to you.. Thanks.

              D 1 Reply Last reply
              0
              • P Palash Biswas

                Sorry some mistake was there i did not want to post the message to you.. Thanks.

                D Offline
                D Offline
                developerit
                wrote on last edited by
                #7

                the code which you have send where we have to write the code.and can you give small example for this...

                P 1 Reply Last reply
                0
                • D developerit

                  the code which you have send where we have to write the code.and can you give small example for this...

                  P Offline
                  P Offline
                  Palash Biswas
                  wrote on last edited by
                  #8

                  Put this below attribute in the top of your Page Code behind and Name Parameter is the permitted user for this page.... [PrincipalPermission(SecurityAction.Demand,Name=@"kovairindia\palash",Unrestricted=false)] Thanks

                  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