将文件写入网络Samba共享 [英] Writing a file to network Samba Share

查看:171
本文介绍了将文件写入网络Samba共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我想将页面的输出写入驻留在samba共享中的txt文件中.有两种方案.
1.在开发机器上.
2.在托管服务器上.

现在我只关心开发机器.在我的asp.net应用程序中,我有一个页面,输出应该写到samba共享中的txt文件中.它在网络中.

我无权访问samba分享.我们创建了一个本地用户,可以访问此共享.当我尝试在Windows运行命令中登录samba共享并执行我的代码时,它工作正常.

但是,如果从samba共享注销并再次执行该代码,它将抛出未知的用户名或错误的密码错误".

这是我的代码.

新更新
我在Windows run命令中使用正确的凭据登录到samba共享,然后使用错误的凭据执行了代码,然后它也能正常工作.我现在很困惑.

Hi All,
I want to write an output from a page into a txt file which resides in a samba share. There are two Scenarios.
1. On development machine.
2. On hosting server.

Now i am only concerned about development machine. In my asp.net application i have a page, the output should be written to a txt file in a samba share. it is in network.

I have no access to samba share. we have created a local user with all access to this share. When i try loging into samba share in windows run command and executing my code it works fine.

But if log off from samba share and again execute the code it will throw "Unknown username or bad password error."

Here is my code.

New Update
I logged into samba share with correct credentials in windows run command and then i executed the code with false credentials, Then also it works fine. I am totally confused now.

System.Net.WebResponse response;
String strMSG = string.Empty;
WebRequest myReq = WebRequest.Create("file://inecsamba/hardware/hosts.txt");
myReq.PreAuthenticate = true;
NetworkCredential networkCredential = new NetworkCredential("username", "pwd");
myReq.Credentials = networkCredential;
myReq.Method = "POST";
try
{
using (var sw = new StreamWriter(myReq.GetRequestStream(), System.Text.Encoding.ASCII))
{
sw.Write("tect to be written");
} 
response = myReq.GetResponse();
strMSG = string.Format("{0} {1}", response.ContentLength, response.ContentType);
}
catch (Exception ex)
{
strMSG = ex.Message;
Label2.Text = strMSG;
}




此用户名和密码是localaccount用户名和密码.

请帮助我.我对网络连接一无所知.

如果需要,我可以提供更多详细信息.




this username and pwd is localaccount username and password.

Please help me in this . I don''t know more about network connection.

If needed i can provide much more details.

推荐答案

与msdn示例相比,您的代码看起来不错:
http://msdn.microsoft.com/zh-cn/library/system.net.webrequest.credentials%28v = vs.71%29.aspx [网络共享和UNC路径 [ http://platinumdogs.wordpress.com/2008/10/30 /net-c-impersonation-with-network-credentials/ [
Your code looks fine compared to the msdn example:
http://msdn.microsoft.com/en-us/library/system.net.webrequest.credentials%28v=vs.71%29.aspx[^]

Maybe you could also have a look at the links below and try if they get better results.
Network Shares and UNC paths[^]

http://platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/[^]

Good luck!


这篇关于将文件写入网络Samba共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆