ASMX: Setting User/Password at run-time

∥☆過路亽.° 提交于 2019-12-12 03:51:46

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/3016739/asmx-setting-user-password-at-run-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!