Exit constructor in abstract class
-
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.
-
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.
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.
-
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.
I was afraid of this :( This would mean that i have to check for this flag on like 150 classes :(( This sucks.
-
I was afraid of this :( This would mean that i have to check for this flag on like 150 classes :(( This sucks.
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.
-
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.
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.
-
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 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)
-
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)
OK, sounds good. Thank you.