简体   繁体   English

从asp.net应用程序访问网络共享。 在Visual Studio中工作,但在IIS中工作,为什么?

[英]Access a network share from an asp.net app. Works in Visual Studio but not in IIS, why?

I have a network share in the intranet that allows write access to everyone (guest) 我在Intranet中有一个网络共享,该共享允许对所有人(来宾)的写访问

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. 因此,我在c#中编写了一个程序(mojoportal模块,无论如何都是这样),该程序在该路径中写入了一些文件,并且在Visual Studio中效果很好。

Now, using the same program in IIS 7.5, does not work, i get this exception: 现在,在IIS 7.5中使用相同的程序不起作用,我得到此异常:

System.Net.WebException: An exception occurred during a WebClient request. System.Net.WebException:WebClient请求期间发生异常。 ---> System.IO.IOException - Logon failure: unknown user name or bad password. ---> System.IO.IOException-登录失败:用户名未知或密码错误。

Well... since the access on the smb share is granted to everybody, i don't understand why it does not work on IIS... 嗯...由于smb共享的访问权限已授予所有人,我不明白为什么它在IIS上不起作用...

The code is this: 代码是这样的:

WebClient wc = new WebClient();
wc.DownloadFile(urltodownload, smbshare);

What it can be? 可以是什么? Thanks 谢谢

Your IIS service not granted to access file share by default. 默认情况下,未授予您的IIS服务访问文件共享的权限。 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: 您可以尝试将应用程序池标识设置为Local System来运行站点,或者手动控制从web.config执行代码所使用的标识:

<system.web>
  <identity impersonate="true" userName="user with correct rights or admin" password="password"/>
  ...

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... 我相信,每个人组仍然需要某种有效的凭证,而无需设置您是匿名的凭证...

wc.Credentials = CredentialCache.DefaultCredentials;

It looks like its not an issue with accessing the SMB share, its an issue accessing the website stored in urltodownload . 看起来访问SMB共享不是问题,访问urltodownload存储的网站也不是问题。 Like Richard said, you may want to use the default credentials ie wc.UseDefaultCredentials = true; 就像Richard所说的,您可能要使用默认凭据,即wc.UseDefaultCredentials = true; or some specific set of credentials or set up the web site at urltodownload to accept anonymous connections. 或某些特定的凭据集,或在urltodownload上设置网站以接受匿名连接。

Refer to what can cause WebException for the DownloadFile method @ MSDN . 有关DownloadFile方法@ MSDN,请参阅导致WebException的原因。

You need some kind of credentials to use a share from asp.net. 您需要某种凭据才能使用来自asp.net的共享。 You can setup an impersonation on the web.config or set wc.Credentials using network credentials. 您可以在web.config上设置模拟或使用网络凭据设置wc.Credentials。 In the web.config you would set the follwoing under the system.web section: 在web.config中,您可以在system.web部分下设置以下内容:

<identity impersonate="true" userName="username_here" password="password_here" />

For my Visual Studio application (WinForms), it was a simple act of creating a strong name key (SNK) for the application to use. 对于我的Visual Studio应用程序(WinForms),这是创建供应用程序使用的强名称键(SNK)的简单操作。

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. 也许在Visual Studio中创建SNK可以设置我上面其他作者所指的这些凭据。

Hope this helps. 希望这可以帮助。

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

相关问题 从网络共享下载 ASP.NET Core(有时有效?) - ASP.NET Core download from a Network Share (sometimes works?) ASP.Net Core应用程序可在Visual Studio中运行,但不能与dotnet运行 - ASP.Net Core app works in visual studio but not with dotnet run ASP.Net WebApi MapHttpRoute在Visual Studio上有效,但在WebForm应用程序中的IIS上无效 - ASP.Net WebApi MapHttpRoute works on Visual Studio but doesn't work on IIS in a WebForm application 无法调试在Visual Studio 2015上开发并托管在IIS上的asp.net Web应用程序 - Can't debug my asp.net web app developped on visual studio 2015 and hosted on IIS Visual Studio / Asp.net / IIS路径帮助 - Visual Studio/ Asp.net / IIS Pathing Help 在asp.net上使用axapta businessconnectornet导致Visual Studio / IIS崩溃 - Visual Studio / IIS Crashing using axapta businessconnectornet on asp.net IIS的Visual Studio Team Services asp.net核心版本 - Visual Studio Team Services asp.net core build for IIS 无法从IIS(内部服务器500)使用Visual Studio 2015运行简单ASP.NET MVC应用程序 - Cannot run Simple ASP.NET MVC Application with Visual Studio 2015 from IIS (Internal Server 500) 在没有Visual Studio的计算机上从IIS运行ASP.Net网页 - Run a ASP.Net webpage from IIS in a machine without Visual Studio 无法从asp.net Web表单访问网络共享 - Trouble accessing network share from asp.net web form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM