问题
I want to connect xml file in remote server. I wrote my code like this:
string XMLPATH = @"\\10.222.54.141\c$\Data\CL\Casinolink30\BuildFiles\Logging\980\NoLog4NetFile.UnitTest.Tests.nunit-results.xml";
FileWebRequest request = (FileWebRequest)FileWebRequest.Create(XMLPATH);
request.Credentials = new NetworkCredential("administrator", "Igtcorp123");
FileWebResponse response = request.GetResponse() as FileWebResponse;
Stream stReader = response.GetResponseStream();
XmlTextReader reader = new XmlTextReader(stReader);
int count = 100;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "test-case")
{
//Console.WriteLine("testcase name:" + reader.GetAttribute("name"));
Console.WriteLine("testcase info");
Console.WriteLine("name: " + reader.GetAttribute("name").ToString());
//Console.WriteLine("success: " + reader.GetAttribute("success").ToString());
Console.WriteLine("------------------------------------");
}
}
}
I got a error: "logon failure: unknown user name or bad". and I try to do this:
- input the address (10.222.54.141\c$\Data\CL\Casinolink30\BuildFiles\Logging\980\NoLog4NetFile.UnitTest.Tests.nunit-results.xml) to the address bar,and open. A dialog show up let me add user name and password. I typed in right word, and I successfully accessed the file.
- I run the code above. I successfully got the data.
- I try this program in another computer. They can access the address, but the program does not work.
I am confused about this? Why does this happen?
Now I deployed my project to the server, I can successfully get my data in localhost address(http://localhost:61547/) on server. But I can not get data in my computer remotely through addr: http://10.222.54.140:8080/. What happen? Can any one help me? Much appreciate.
回答1:
Try changing the app.config file a bit:
<system.net>
<defaultProxy useDefaultCredentials="false">
<proxy usesystemdefault="true"/>
</defaultProxy>
</system.net>
This might solve the problem.
You can add this as below in the Web.config file:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.net>
<defaultProxy useDefaultCredentials="false">
<proxy usesystemdefault="True"/>
</defaultProxy>
</system.net>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
来源:https://stackoverflow.com/questions/10242990/logon-failure-unknown-user-name-or-bad-password-but-i-am-using-the-right-usern