클라이언트 요구 사항 중 하나는 서버가 파일을 생성하고 특수 폴더에 저장한다는 것입니다. 이 파일은 사용자가 수정하거나 삭제할 수 없습니다. 그래서 내가 생각한 유일한 방법은 상승 된 권한으로이 파일을 생성하여 일반 사용자가 파일을 삭제하거나 수정할 수 없도록하는 것입니다. 하지만 문제는 일반 사용자가이 파일과 상호 작용할 수있는 권한을 가진 파일을 어떻게 생성 할 수 있습니까? 서버에서만 다운로드 할 수 있습니다.Visual Basic을 사용하여 ASP.net에서 특별한 권한을 가진 서버에 파일을 만드는 방법은 무엇입니까?
이 코드를 사용하여 파일을 생성합니다 ... 그러나 권한 상승을 위해이 코드를 구성하는 방법을 모르겠습니다. 이 서버에있는 파일을 생성하는 기능입니다
Protected Sub ibtGenerar_OnClick(ByVal sender As Object, ByVal e As ImageClickEventArgs)
oArchivoTelecredito.NombreArchivo = txtNombreArchivo.Text
oArchivoTelecredito.SesionDetalleArchivosTelecredito = New List(Of DetalleArchivoTelecreditoBE)
Dim oArchivoTelecreditoSL As New ArchivoTelecreditoSL
Response.AddHeader("Content-disposition", "attachment;filename=" & oArchivoTelecredito.NombreArchivo & ".txt")
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(oArchivoTelecreditoSL.GeneraArchivoTelecredito(oArchivoTelecredito, Server.MapPath(oArchivoTelecredito.NombreArchivo)))
Response.End()
End Sub
:
Public Function GeneraArchivoTelecredito(ByVal telecredito As ArchivoTelecreditoBE, ByVal ruta As String) As Byte()
Dim lineas As Integer = telecredito.SesionDetalleArchivosTelecredito.Count + 1
Dim registro(0 To lineas) As String
registro(0) = Me.ObtenerCabeceraArchivoTelecredito(telecredito)
Dim archivo = ruta & ".txt"
Using escritor As New StreamWriter(archivo)
For index = 0 To lineas
escritor.WriteLine(registro(index))
Next
escritor.Close()
End Using
Dim lector As FileStream
lector = File.Open(archivo, FileMode.Open)
Dim bytes(lector.Length) As Byte
lector.Read(bytes, 0, lector.Length)
lector.Close()
Return bytes
End Function
파일을 읽기 전용으로 설정하려면 File.SetAttributes ("PathToFile", FileAttributes.ReadOnly)를 사용할 수 있습니다. – jmaglio
될 수 있습니다. 하지만 파일을 삭제할 수 없도록하고 싶습니다. 가능한가? – jcvegan
이 게시물보기 - http://serverfault.com/questions/3878/is-there-a-way-to-prevent-a-file-from-being-deleted - 디렉토리에 대한 권한을 설정해야합니다. 파일 자체. – jmaglio