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. General Programming
  3. Visual Basic
  4. Exit constructor in abstract class

Exit constructor in abstract class

Scheduled Pinned Locked Moved Visual Basic
questioncsharpasp-netdatabasesecurity
7 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.
  • E Offline
    E Offline
    Enver Maroshi
    wrote on last edited by
    #1

    Hi guys, i need help. Below i c/p code, to explain in short, in abstract class i have login authentication, i inherit that abstarct class on all other classes that i need to be secured, now what i wan tis that if my abstract class does invalidate user, to be stoped and render login page, otherwise it will continue processing and on end render index page. Public Class Secure      Public Sub New()           If Not User.Authenticated Then                RenderLogin()           End If      End Sub End Class Public Class Index      Inherits Secure      Public Sub New()           LoadMessages()           LoadTasks()           RenderIndex()      End Sub End Class The question is, how do i stop further executing after RenderLogin() method? I don't want it to continue constructing new Index class. Btw, all this is run inside http context, but i did put it in here and not in asp.net since this has more got to do with VB and classes than with asp. Oh, and i know i can write Response.End, but i would like to avoid this - because of "System.Threading.ThreadAbortException" errors which go on my nerves.

    C 1 Reply Last reply
    0
    • E Enver Maroshi

      Hi guys, i need help. Below i c/p code, to explain in short, in abstract class i have login authentication, i inherit that abstarct class on all other classes that i need to be secured, now what i wan tis that if my abstract class does invalidate user, to be stoped and render login page, otherwise it will continue processing and on end render index page. Public Class Secure      Public Sub New()           If Not User.Authenticated Then                RenderLogin()           End If      End Sub End Class Public Class Index      Inherits Secure      Public Sub New()           LoadMessages()           LoadTasks()           RenderIndex()      End Sub End Class The question is, how do i stop further executing after RenderLogin() method? I don't want it to continue constructing new Index class. Btw, all this is run inside http context, but i did put it in here and not in asp.net since this has more got to do with VB and classes than with asp. Oh, and i know i can write Response.End, but i would like to avoid this - because of "System.Threading.ThreadAbortException" errors which go on my nerves.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      There is no way to stop a constructor from working except perhaps for throwing an exception. A better design would be to set a flag, so that you can check the flag from the client class to see if login succeeded.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      E 1 Reply Last reply
      0
      • C Christian Graus

        There is no way to stop a constructor from working except perhaps for throwing an exception. A better design would be to set a flag, so that you can check the flag from the client class to see if login succeeded.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        E Offline
        E Offline
        Enver Maroshi
        wrote on last edited by
        #3

        I was afraid of this   :( This would mean that i have to check for this flag on like 150 classes   :(( This sucks.

        C 1 Reply Last reply
        0
        • E Enver Maroshi

          I was afraid of this   :( This would mean that i have to check for this flag on like 150 classes   :(( This sucks.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          It means the overall design is flawed.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          E 1 Reply Last reply
          0
          • C Christian Graus

            It means the overall design is flawed.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            E Offline
            E Offline
            Enver Maroshi
            wrote on last edited by
            #5

            Do you maybe have an idea how could i create it right way. I will wrote in short what i try to make, and if you have time, maybe you could give me an example how would be best to make. I have a bunch of classes, like UserEdit, UserList, TaskEdit, TaskList, each of this class has some of it's methods, like UserEdit has Add, Update, View and Delete. Each of this class and method has a restriction based on user, so a specific user can use method Add in class UserEdit. So, to avoid check on each class, how could i make this check in abstract class? I know that best would be to have this check in children (class that inherits abstract class) and on method level, but that is a lot of work to implement in each class. So, do you have any idea? Also, UserEdit might have Add method, but TaskEdit does not neccessery have one.

            I 1 Reply Last reply
            0
            • E Enver Maroshi

              Do you maybe have an idea how could i create it right way. I will wrote in short what i try to make, and if you have time, maybe you could give me an example how would be best to make. I have a bunch of classes, like UserEdit, UserList, TaskEdit, TaskList, each of this class has some of it's methods, like UserEdit has Add, Update, View and Delete. Each of this class and method has a restriction based on user, so a specific user can use method Add in class UserEdit. So, to avoid check on each class, how could i make this check in abstract class? I know that best would be to have this check in children (class that inherits abstract class) and on method level, but that is a lot of work to implement in each class. So, do you have any idea? Also, UserEdit might have Add method, but TaskEdit does not neccessery have one.

              I Offline
              I Offline
              Ian Shlasko
              wrote on last edited by
              #6

              I don't see a way to avoid modifying all of the child classes, but do it right, and you'll only need to do it once. 1) Make an overridable/virtual Initialize() method in the base class 2) Move all of the construction code in the child classes into the Initialize() override. 3) In the base constructor, either call the Initialize() method or don't. Obviously, you don't have to call it Initialize()... Whatever name is more suitable.

              Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

              E 1 Reply Last reply
              0
              • I Ian Shlasko

                I don't see a way to avoid modifying all of the child classes, but do it right, and you'll only need to do it once. 1) Make an overridable/virtual Initialize() method in the base class 2) Move all of the construction code in the child classes into the Initialize() override. 3) In the base constructor, either call the Initialize() method or don't. Obviously, you don't have to call it Initialize()... Whatever name is more suitable.

                Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

                E Offline
                E Offline
                Enver Maroshi
                wrote on last edited by
                #7

                OK, sounds good. Thank you.

                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