简体   繁体   English

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

[英]ASMX: Setting User/Password at run-time

When I want to connect to my web service If I write it like this: 当我想连接到我的Web服务时如果我这样写:

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: 所以我要创建一个NetworkCredential实例,并根据从该登录表单获得的内容来设置其用户/密码成员,然后而不是使用上面的行来编写此代码:

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

but in this way when I call a method of that webService, it gives me errors . 但是以这种方式,当我调用该webService的方法时,会给我errors。

Is it the wrong way to set credentials? 设置凭据的方法是否错误?

Are you including the domain name when you create your NetworkCredential? 创建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. 帕特里克。

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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM