|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
OK, sounds good. Thank you.
|
|
|
|
|
Hi to all, am new with VB.net an need help with events handling.
From the following code, How can I identify which of the two event was triggered. Is this possible?
Private Sub BHDay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHDay.TextChanged, BHDay.LostFocus
Some Validation Code...
End Sub
Thanks,
|
|
|
|
|
There's no way to tell which event triggered the handler using this code.
A better method would be to break this into two seperate handlers.
Private Sub BHDay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHDay.TextChanged
' Code to handle specific case of TextChanged
' Then call CommonCode to execute code that should run if either event is triggered.
End Sub
Private Sub BHDay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BHDay.LostFocus
' Code to handle specific case of LostFocus
' Then call CommonCode to execute code that should run if either event is triggered.
End Sub
Private Sub CommonCode()
End Sub
|
|
|
|
|
Abit stuck at the moment
I need some help all i need to do is to copy the content of a.txt into b.txt?
i don't really know where to start, so if anybody can help that would be great
Cheers
Dan
|
|
|
|
|
Like d@nisch explained[^], check out the System.IO namespace. The method CopyTo [^] does what you're looking for - it copies the contents of file A into file B.
I are Troll
|
|
|
|
|
Dim contents As String = My.Computer.FileSystem.ReadAllText("a.txt")
My.Computer.FileSystem.WriteAllText("b.txt", contents, False)
|
|
|
|
|
This is the third time you've asked this. The second time was only a few hours before this time. Perhaps you should continue to reply on the older thread, when it's still visible ? Perhaps when you decide you need to ask again, you should explain what you were told before, what you tried, and why you're still stuck ?
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.
|
|
|
|
|
This is the code:
With Adodc1.Recordset
.MoveFirst()
Do While .EOF = False
Debug.Print(.Fields("Name").Value)
.MoveNext()
Loop
End With
The problem: Adodc1.Recordset.Eof is never set to False thus the loop never ends. Is this a bug in VB or is there some option/parameter that I'm not using?
|
|
|
|
|
If you are using VB Express 2008, why are you still using RecordSet?
Shouldn't you be trying to move this to DataSet?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for your reply. Use of Datasets is another topic. The VB Express documentation clearly states "You can use the BOF and EOF properties to determine whether an Recordset object contains rows or whether you have gone beyond the limits of an Recordset as you move from row to row."
|
|
|
|
|
Sorry for the delay in responding, I had to step out for a while.
Les Singletary wrote: The VB Express documentation clearly states "You can use the BOF and EOF properties to determine whether an Recordset object contains rows or whether you have gone beyond the limits of an Recordset as you move from row to row."
What a shame they don't give an example.
I searched on my local MSDN before my previous reply and all I could find was the ADO compared to ADO.Net page for a search for RecordSet. For EOF I got a reference to a completely unrelated Eof() function.
Since your reply I Googled Recordset.EOF and got quite a lot of hits although not many had code samples. One I looked at suggested
Do While Not .EOF
........
.......
Loop
If you haven't already solved this, I hope that this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks again. I too found lots of usless post on the web for RecordSet.Eof. The example you posted depends on VB correctly setting the .Eof property when that event occurs, which as far as I can determine, it does not.
|
|
|
|
|
Yes, it does. I tried it with a small query and had no issues. VB doesn't set that value, the internals of the ADODB object does.
|
|
|
|
|
Yes, I know that the AdoDb works as I said. The problem is with AdoDc.
|
|
|
|
|
The answer doesn't change. That property value is only set by the internals of the object, not by VB.
|
|
|
|
|
I am trying to remember something weird about the .BOF and .EOF properties from certain data access controls from my Delphi Days. It went something along the lines that if you set .BOF to true it actually 'points' to an imaginary record one before the physical BOF. So I am wondering if there might be something similar going on in your case. i.e. Is there just one record returned and .EOF is pointing past that record.
I hope that that makes some sort of sense. Trying to explain it to anyone always confused me in Delphi and it appears not to have got any better.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
You have VB.NET Express and you're using the old ADO Data Control?? Why?? The ADO.NET methods are faster and more flexible.
No, this isn't a bug in VB. How many records were returned in the query?
|
|
|
|
|
Thanks for your reply. Using ADO.NET is another matter. The number of records returned depends on the number of records in the database at the time. I know how to "get around" this problem. However, I am searching for an answer to how to get the ADODC control to function properly using the .RecordSet.Eof property. BTW, the ADODB object functions correctly.
|
|
|
|
|
Les Singletary wrote: Using ADO.NET is another matter.
That doesn't answer the question. Using ADO.NET instead of deprecated, obsolete objects, would most assuredly solve your problem, as well as prevent others, such a binding controls to your data. You cannot bind any .NET control or class to the data held in the old ADOxx objects. This severely limits your ability to do data manipulation while using those objects.
|
|
|
|