次のコードは、Cassiniでは正常に動作しますが、IISでは正常に動作しません。私はfile not found
を取得し、C:\ test.pdf(IISのアクセス許可をテストする)をテストしたときにリモート共有またはローカルでファイルを取得できません。Windows 2008R2のIISでAdmin.jpgが動作しません。 VS2010の下で動作Cassini
このアプリケーションの目的は、セキュアなURLで検索されるファイル。セキュリティコードはこのサンプルから除外されています。私はちょうどこのプレーンバニラサンプルのファイルへのアクセスに焦点を当てています。
私は
- アプリケーションプール(プロセスモデルのアイデンティティが)
- ウェブサイトの物理パスの資格情報が同じ管理者アカウント
- 管理者アカウントで実行されているドメイン管理者アカウントを実行していることを確認してください作りましたローカルポリシーには
Batch
とRun as a Service
の両方の権利があります。
私は、次のURLテストシステムとカッシーニの下
http://localhost:1651/services/GetFile.svc/get?swt=\\remoteserver\share\file.pdf
[ServiceContract(SessionMode = SessionMode.NotAllowed)]
public interface IGetFile
{
[OperationContract]
[WebGet(UriTemplate = "/get?swt={filename}", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
Stream Get(string filename);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class GetFile : IGetFile
{
bool debug = true;
public Stream Get(string filename)
{
//this will cause the file dialog to show the file name instead of "get"
WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-disposition", string.Format("inline; filename={0}", filename));
WebOperationContext.Current.OutgoingResponse.ContentType = "application/octect-stream";
FileStream fs1= null;
//WindowsIdentity winId = new WindowsIdentity("[email protected]");
//using (winId.Impersonate())
{
try
{
fs1 = File.OpenRead(filename);
}
catch (FileNotFoundException e)
{
if (debug)
throw;
else
return null;
}
catch (IOException e)
{
if (debug)
throw;
else
// message: Either a required impersonation level was not provided, or the provided impersonation level is invalid.
return null;
}
}
return fs1;
から読み取ることができる読み取り権限を持っていますファイル? –
はい、そうです(そうでないと思わない限り)。私は、IISが実行されている権限で質問をより明確にしました。 – LamonteCristo