당신의 문제 설명에서 나는 Custom HttpHandlers
이 당신을위한 올바른 선택이라고 생각합니다. 당신은 어떤 유형의 파일이 귀하의 폴더에 존재하는지 언급하지 않았으며, 간결함을 위해 PDF 파일을 가지고 있다고 가정하여 대답 할 것입니다.
응용 프로그램에 다른 사용자가 있다고 언급 했으므로 .NET 기본 인증 관리자와 역할 공급자를 사용해야합니다. 간단한 보안 프레임 워크 설정을 통해 web.config protected 폴더 뒤에 PDF 파일을 웹 응용 프로그램에 배치합니다. 그런 다음 사용자 정의 HTTP 처리기를 만들어 정적 문서에 대한 액세스를 볼 수 있어야하는 사용자로만 제한합니다 그것.
샘플 HTTP 처리기 :
public class FileProtectionHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
{
// Is the user logged-in?
if (!context.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
return;
}
string requestedFile =
context.Server.MapPath(context.Request.FilePath);
// Verify the user has access to the User role.
if (context.User.IsInRole("User"))
{
SendContentTypeAndFile(context, requestedFile);
}
else
{
// Deny access, redirect to error page or back to login
//page.
context.Response.Redirect("~/User/AccessDenied.aspx");
}
break;
}
}
}
방법 SendContentTypeAndFile :
private HttpContext SendContentTypeAndFile(HttpContext context, String strFile)
{
context.Response.ContentType = GetContentType(strFile);
context.Response.TransmitFile(strFile);
context.Response.End();
return context;
}
private string GetContentType(string filename)
{
// used to set the encoding for the reponse stream
string res = null;
FileInfo fileinfo = new FileInfo(filename);
if (fileinfo.Exists)
{
switch (fileinfo.Extension.Remove(0, 1).ToLower())
{
case "pdf":
{
res = "application/pdf";
break;
}
}
return res;
}
return null;
}
마지막 단계는의 webconfig에 을이 HTTP 처리기를 구성 할 필요가 있다는 것입니다 그리고 당신은 더 볼 수 있습니다 정보 here
여기에 완전한입니다. 0
https :를 통해 기본 인증을 사용하고 파일 공유에 대한 액세스를 가장 할 수 있습니다. –
양식 인증을 사용하는 또 다른 이유는 브라우저가 자격 증명을 묻는 메시지가 아닌 사용자 지정 로그인 양식을 필요로하기 때문입니다. 그래서 우리는 그대로 폼 승인을 유지할 것입니다. 문제는 파일 시스템에 안전하게 액세스하는 방법에 있습니다. – Primoz
당신은 위장이 더 이상 권고되지 않는다는 것을 어디에서 읽었습니까? 이 문제에 잘 맞는 것 같습니다. –