By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,238 Members | 1,485 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,238 IT Pros & Developers. It's quick & easy.

Authentication, Remoting, and Database Access problem

P: n/a
I am trying to setup a solution that will include a client which will access
a database via remoting calls. I am hosting my remoting project in IIS, and
am using Windows Integrated security. Since some of my users will be coming
in through the web (from non-trusted domains) to log into their local domain
account, I am trying to implement a login screen which will gather the user
data (login, pwd, domain). The login screen will be displayed only if the
user's default credentials do not authenticate. I have setup a small test
project to work out the kinks in the process, with the remoting part having
2 methods:
GetMessage() - Returns a string that includes the
HttpContext.Current.User.Identity.Name but has no
database access
GetMostExpensiveProducts - Creates a connection to the NorthWind
database and executes the
[Ten Most Expensive] stored procedure

I have found that if I allow the default credentials to go through, both
calls work correctly. However, when I create a set of credentials from the
login screen, the GetMessage shows the proper username (in domain\username
form) but the GetMostExpensiveProducts call errors with the following error
message:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

The GetMostExpensiveProducts has the following connection string:
"Provider=SQLOLEDB;Data Source=Dev2k;Initial Catalog=Northwind;
Integrated Security=SSPI;Trusted_Connection=yes"

The code on the client to create and set the credentials looks like this:
Dim _NWInfo As iNWInfo
Dim serverCredentials As New NetworkCredential
Dim channelproperties As IDictionary
Dim serverURL As String =
"http://localhost/dotNET/RemotingTest/NWInfo.rem"

...

_NWInfo =
CType(Activator.GetObject(GetType(RemotingInterfac e.iNWInfo), serverURL),
RemotingInterface.iNWInfo)

channelproperties =
ChannelServices.GetChannelSinkProperties(_NWInfo)
'Comment out the next line to cause 401 error and force manual login
to happen
'channelproperties("credentials") =
CredentialCache.DefaultCredential

Try
txtResults.Text = txtResults.Text & vbCrLf & _NWInfo.GetMessage
Catch ex As System.Net.WebException When ex.Message.indexof("401") >
0
Dim loginDlg As New Login
loginDlg.ShowDialog()
If loginDlg.DialogResult = Windows.Forms.DialogResult.OK Then
serverCredentials.UserName = loginDlg.txtUserName.Text
serverCredentials.Password = loginDlg.txtPassword.Text
serverCredentials.Domain = loginDlg.txtDomain.Text
loginDlg.Close()
End If
channelproperties("credentials") = serverCredentials

txtResults.Text = txtResults.Text & vbCrLf & _NWInfo.GetMessage
Catch ex As System.Net.WebException When ex.Message.IndexOf("could
not be resolved") > 0
txtResults.Text += vbCrLf & "I couldn't find the server you
specified: " & serverURL
Catch ex As Exception
txtResults.Text = txtResults.Text & vbCrLf & ex.Message & vbCrLf
& ex.Source & vbCrLf & _
GetType(Exception).ToString
End Try
txtResults.Text = txtResults.Text & vbCrLf & _NWInfo.GetMessage

Can anyone tell me what I am doing wrong here?

TIA
Ron L

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I think I found the problem. I had the <identity impersonate="true">
directive in the system.runtime.remoting | application | Channels section of
my Web.Config. When I copied it the System.Web section, my connection
started to work.

Ron L

"Ron L" <ro**@bogus.Address.com> wrote in message
news:u$**************@TK2MSFTNGP10.phx.gbl...
I am trying to setup a solution that will include a client which will
access a database via remoting calls. I am hosting my remoting project in
IIS, and am using Windows Integrated security. Since some of my users will
be coming in through the web (from non-trusted domains) to log into their
local domain account, I am trying to implement a login screen which will
gather the user data (login, pwd, domain). The login screen will be
displayed only if the user's default credentials do not authenticate. I
have setup a small test project to work out the kinks in the process, with
the remoting part having 2 methods:
GetMessage() - Returns a string that includes the
HttpContext.Current.User.Identity.Name but has no
database access
GetMostExpensiveProducts - Creates a connection to the NorthWind
database and executes the
[Ten Most Expensive] stored procedure

I have found that if I allow the default credentials to go through, both
calls work correctly. However, when I create a set of credentials from
the login screen, the GetMessage shows the proper username (in
domain\username form) but the GetMostExpensiveProducts call errors with
the following error message:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

The GetMostExpensiveProducts has the following connection string:
"Provider=SQLOLEDB;Data Source=Dev2k;Initial Catalog=Northwind;
Integrated Security=SSPI;Trusted_Connection=yes"

The code on the client to create and set the credentials looks like this:
Dim _NWInfo As iNWInfo
Dim serverCredentials As New NetworkCredential
Dim channelproperties As IDictionary
Dim serverURL As String =
"http://localhost/dotNET/RemotingTest/NWInfo.rem"

...

_NWInfo =
CType(Activator.GetObject(GetType(RemotingInterfac e.iNWInfo), serverURL),
RemotingInterface.iNWInfo)

channelproperties =
ChannelServices.GetChannelSinkProperties(_NWInfo)
'Comment out the next line to cause 401 error and force manual
login to happen
'channelproperties("credentials") =
CredentialCache.DefaultCredential

Try
txtResults.Text = txtResults.Text & vbCrLf & _NWInfo.GetMessage
Catch ex As System.Net.WebException When ex.Message.indexof("401")
> 0

Dim loginDlg As New Login
loginDlg.ShowDialog()
If loginDlg.DialogResult = Windows.Forms.DialogResult.OK Then
serverCredentials.UserName = loginDlg.txtUserName.Text
serverCredentials.Password = loginDlg.txtPassword.Text
serverCredentials.Domain = loginDlg.txtDomain.Text
loginDlg.Close()
End If
channelproperties("credentials") = serverCredentials

txtResults.Text = txtResults.Text & vbCrLf & _NWInfo.GetMessage
Catch ex As System.Net.WebException When ex.Message.IndexOf("could
not be resolved") > 0
txtResults.Text += vbCrLf & "I couldn't find the server you
specified: " & serverURL
Catch ex As Exception
txtResults.Text = txtResults.Text & vbCrLf & ex.Message &
vbCrLf & ex.Source & vbCrLf & _
GetType(Exception).ToString
End Try
txtResults.Text = txtResults.Text & vbCrLf & _NWInfo.GetMessage

Can anyone tell me what I am doing wrong here?

TIA
Ron L

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.