ASMX:在运行时设置用户/密码

发布于 2024-09-05 07:43:38 字数 435 浏览 4 评论 0原文

当我想连接到我的网络服务时如果我这样写:

m_TransferServiceSoap.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

它正在工作。但我需要一个登录表格。这样用户就可以输入他们的用户/通行证

,所以我正在创建一个 NetworkCredential 实例,并根据我从登录表单中获得的内容设置其用户/通行证成员,然后我不使用上面的行,而是编写了这一行:

m_TransferServiceSoap.Credentials = userpass; // the instance above.

但是以这种方式,当我调用该 webService 的方法,它给我错误。

设置凭据的方式是否错误?

When I want to connect to my web service If I write it like this:

m_TransferServiceSoap.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

it is working. but I need a Login Form. so users can enter their user/pass

so I am creating a NetworkCredential instance and setting its user/pass members from what I get from that login form and then instead of using the line above I am writing this one:

m_TransferServiceSoap.Credentials = userpass; // the instance above.

but in this way when I call a method of that webService, it gives me errors .

Is it the wrong way to set credentials?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捎一片雪花 2024-09-12 07:43:38

您在创建 NetworkCredential 时是否包含域名?

通话内容应如下所示:

var nc = new NetworkCredential( "Name","Password","Domain Name"); 

我已将其添加为答案,以便如果有效,我可以提出要点...

帕特里克。

Are you including the domain name when you create your NetworkCredential?

the call should look something like this:

var nc = new NetworkCredential( "Name","Password","Domain Name"); 

I've added this as an answer so that, if it worked, I can can the points...

Patrick.

执笔绘流年 2024-09-12 07:43:38

这对我有用

myservice g = new myservice();
g.AuthenticationHeaderValue = new AuthenticationHeader();
//Authentication values
g.AuthenticationHeaderValue.UserName = "sdaaad";
g.AuthenticationHeaderValue.Password = "sbvbfb#%$3df";

this is what worked for me

myservice g = new myservice();
g.AuthenticationHeaderValue = new AuthenticationHeader();
//Authentication values
g.AuthenticationHeaderValue.UserName = "sdaaad";
g.AuthenticationHeaderValue.Password = "sbvbfb#%$3df";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文