如何使用visual basic在具有Asp.net特权的服务器上创建文件?

如何使用visual basic在具有Asp.net特权的服务器上创建文件?,asp.net,vb.net,Asp.net,Vb.net,客户机要求之一是服务器生成文件并将其存储在特殊文件夹中。用户无法修改或删除创建的此文件。 因此,我认为唯一的方法是以提升的权限生成这些文件,这样普通用户就不能删除或修改它们。 但问题是我如何生成一个具有普通用户可以与此文件交互的权限的文件。。。仅从服务器下载 我使用此代码生成文件。。。但我不知道如何将其配置为提升权限 这是生成文件并允许下载的按钮: Protected Sub ibtGenerar_OnClick(ByVal sender As Object, ByVal e As ImageC

客户机要求之一是服务器生成文件并将其存储在特殊文件夹中。用户无法修改或删除创建的此文件。 因此,我认为唯一的方法是以提升的权限生成这些文件,这样普通用户就不能删除或修改它们。 但问题是我如何生成一个具有普通用户可以与此文件交互的权限的文件。。。仅从服务器下载

我使用此代码生成文件。。。但我不知道如何将其配置为提升权限

这是生成文件并允许下载的按钮:

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).

您还可以设置目录本身的权限,而不是单个文件的权限-请参阅本文:

如果您想将文件设置为只读,则可以使用file.SetAttributes(“PathToFile”,FileAttributes.ReadOnly)。我可以。但是如果我不允许删除文件。可能吗?请看这篇文章--您可能应该设置目录的权限,而不是文件本身。但是可以在web配置上设置此属性?为什么要在web.config文件中设置属性?如果web应用程序位于应用程序池中,则它应该在某个帐户下运行。授予此帐户在该目录中创建文件的权限,并授予所有普通用户对该目录的只读权限。