?
Solved

detailsview authenticate user before insert

Posted on 2008-11-05
3
Medium Priority
?
260 Views
Last Modified: 2012-05-05
I want to authenticate a user before allowing them to insert a new record.  I have a funtion to check the username and password are correct which returns true or false.

The details view has four fields, projectnumber, customer, startdate, and user.  user is the user id of the authenticated user.

My first question is where do I ask for the password, can I add a password field to the details view or do I need some other mechanism?

Secondly I know there is an ItemInserting for the details view or an inserting event for the sqldatasource, which is best to use and how do I allow the insert if authenticated or block it if not?


    Function AuthenticateUser(ByVal path As String, ByVal user As String, ByVal pass As String) As Boolean
        Dim dirEntry As New DirectoryEntry(path, user, pass)
        Try
            Dim nat As Object
            'if the NativeObject can be created using those credentials
            'then they are valid.
            nat = dirEntry.NativeObject
            Return True
        Catch
            Return False
        End Try
    End Function
0
Comment
Question by:iepaul
  • 2
3 Comments
 
LVL 11

Expert Comment

by:ladarling
ID: 22886167
My first question is where do I ask for the password, can I add a password field to the details view or do I need some other mechanism?
You could ask for the password in the detailsview.. And, In this scenario, I would create a class level boolean variable that indicated whether or not the user was authenticated.
Private UserIsAuthenticated As Boolean = False
And let your authentication function assign that value for the session. If you dont want that authentication to persist you would reset that value after the insert.
Secondly I know there is an ItemInserting for the details view or an inserting event for the sqldatasource, which is best to use and how do I allow the insert if authenticated or block it if not?
Basically, you just handle the ItemInserting event. The parameter object e will be a  DetailsViewInsertEventArgs
You can set its cancel property = True to abort the insert, based on whether the user is validated or not. Doing so in the page itself prevents you from having to rollback datasource changes.
0
 

Author Comment

by:iepaul
ID: 22886664
Do you have any samples of how this would work?  
0
 
LVL 11

Accepted Solution

by:
ladarling earned 2000 total points
ID: 22886818
It will look something like:
Sub CustomerDetail_ItemInserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)
 'If the authentication flag is not set, cancel the insert method completely
If Not UserIsAuthenticated Then e.Cancel = True
End Sub

 
Here is more about the event itself:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.iteminserting.aspx
 
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question