从 ASP.NET 应用程序访问网络共享。在 Visual Studio 中有效,但在 IIS 中无效,为什么?
我在内联网中有一个网络共享,允许每个人(来宾)进行写访问,
所以,我用 C# 编写了一个程序(mojoportal 模块,无论如何,我认为它是相同的),在该路径中写入一些文件,并在 Visual Studio 中工作伟大的。
现在,在 IIS 7.5 中使用相同的程序不起作用,我收到此异常:
System.Net.WebException:异常 在 WebClient 请求期间发生。 ---> System.IO.IOException - 登录失败:用户名未知或错误 密码。
嗯...由于 smb 共享的访问权限授予每个人,我不明白为什么它在 IIS 上不起作用...
代码是这样的:
WebClient wc = new WebClient();
wc.DownloadFile(urltodownload, smbshare);
它可以是什么? 谢谢
I have a network share in the intranet that allows write access to everyone (guest)
So, i wrote a program (mojoportal module, anyway it's the same, i think) in c# that writes some files in that path, and in visual studio works great.
Now, using the same program in IIS 7.5, does not work, i get this exception:
System.Net.WebException: An exception
occurred during a WebClient request.
---> System.IO.IOException - Logon failure: unknown user name or bad
password.
Well... since the access on the smb share is granted to everybody, i don't understand why it does not work on IIS...
The code is this:
WebClient wc = new WebClient();
wc.DownloadFile(urltodownload, smbshare);
What it can be?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
默认情况下,您的 IIS 服务未被授予访问文件共享的权限。您可以尝试将应用程序池标识设置为本地系统来运行您的网站,或者手动控制从 web.config 执行代码的标识:
Your IIS service not granted to access file share by default. You could try run your site with app pool identity set to Local System, or manually control the identity under which code is executed from web.config:
您是否尝试过设置凭据?
我相信每个人组仍然需要某种有效的凭据,而不设置您是匿名的凭据......
Have you tried setting the credentials?
I believe that the everyone group still requires a valid credential of some sort, without setting the credentials you are anonymous...
看起来这不是访问 SMB 共享的问题,而是访问存储在
urltodownload
中的网站的问题。就像理查德所说,您可能想要使用默认凭据,即wc.UseDefaultCredentials = true;
或某些特定的凭据集,或者在urltodownload
设置网站以接受匿名连接。请参阅
DownloadFile
方法可能导致WebException
的原因 @MSDN。It looks like its not an issue with accessing the SMB share, its an issue accessing the website stored in
urltodownload
. Like Richard said, you may want to use the default credentials i.e.wc.UseDefaultCredentials = true;
or some specific set of credentials or set up the web site aturltodownload
to accept anonymous connections.Refer to what can cause
WebException
for theDownloadFile
method @ MSDN.您需要某种凭据才能使用来自 asp.net 的共享。您可以在 web.config 上设置模拟或使用网络凭据设置 wc.Credentials。在 web.config 中,您可以在 system.web 部分下设置以下内容:
You need some kind of credentials to use a share from asp.net. You can setup an impersonation on the web.config or set wc.Credentials using network credentials. In the web.config you would set the follwoing under the system.web section:
对于我的 Visual Studio 应用程序 (WinForms),创建一个强名称密钥 (SNK) 供应用程序使用是一个简单的操作。
我不知道为什么。
也许在 Visual Studio 中创建 SNK 有一种设置这些凭据的方法,我上面的其他作者也提到过。
希望这有帮助。
For my Visual Studio application (WinForms), it was a simple act of creating a strong name key (SNK) for the application to use.
I'm not sure why.
Perhaps creating a SNK in Visual Studio has a way of setting these Credentials that the other authors above me are referring to.
Hope this helps.