Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 服务结构访问unc驱动器以存储文件。可能吗?_C#_Azure_Microservices_Azure Service Fabric_Unc - Fatal编程技术网

C# 服务结构访问unc驱动器以存储文件。可能吗?

C# 服务结构访问unc驱动器以存储文件。可能吗?,c#,azure,microservices,azure-service-fabric,unc,C#,Azure,Microservices,Azure Service Fabric,Unc,我有一个在服务结构(自托管)中运行的服务(.net core)。我试图在互联网上搜索一些资源来帮助我构建一个可能的解决方案,但到目前为止,没有找到可靠的来源 我有两个可能的想法: 1) 像对待任何其他驱动器一样对待unc驱动器,并使用StreamReader和Streamwriter 2) 将文件装载为本地驱动器(以某种方式),并基于 到目前为止,我还不完全理解第二个 它是否能够访问unc驱动器来存储和检索文件? 我该怎么做呢 将unc驱动器作为本地驱动器安装可能是最简单的方法 您可以装载到文件

我有一个在服务结构(自托管)中运行的服务(.net core)。我试图在互联网上搜索一些资源来帮助我构建一个可能的解决方案,但到目前为止,没有找到可靠的来源

我有两个可能的想法: 1) 像对待任何其他驱动器一样对待unc驱动器,并使用StreamReader和Streamwriter

2) 将文件装载为本地驱动器(以某种方式),并基于

到目前为止,我还不完全理解第二个

它是否能够访问unc驱动器来存储和检索文件?
我该怎么做呢

将unc驱动器作为本地驱动器安装可能是最简单的方法

您可以装载到文件共享。将凭据放入配置中。 将脚本作为服务的一部分运行。 确保脚本运行

示例脚本:

$resourceGroupName = "<your-resource-group-name>"
$storageAccountName = "<your-storage-account-name>"
$fileShareName = "<your-file-share-name>"

# These commands require you to be logged into your Azure account, run Login-AzAccount if you haven't
# already logged in.
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$storageAccountKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName
$fileShare = Get-AzStorageShare -Context $storageAccount.Context | Where-Object { 
    $_.Name -eq $fileShareName -and $_.IsSnapshot -eq $false
}

if ($fileShare -eq $null) {
    throw [System.Exception]::new("Azure file share not found")
}

# The value given to the root parameter of the New-PSDrive cmdlet is the host address for the storage account, 
# <storage-account>.file.core.windows.net for Azure Public Regions. $fileShare.StorageUri.PrimaryUri.Host is 
# used because non-Public Azure regions, such as sovereign clouds or Azure Stack deployments, will have different 
# hosts for Azure file shares (and other storage resources).
$password = ConvertTo-SecureString -String $storageAccountKeys[0].Value -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList "AZURE\$($storageAccount.StorageAccountName)", $password
New-PSDrive -Name <desired-drive-letter> -PSProvider FileSystem -Root "\\$($fileShare.StorageUri.PrimaryUri.Host)\$($fileShare.Name)" -Credential $credential -Persist
$resourceGroupName=“”
$storageAccountName=“”
$fileShareName=“”
#这些命令要求您登录Azure帐户,如果尚未登录,请运行登录AzaAccount
#已登录。
$storageAccount=Get-AzStorageAccount-ResourceGroupName$ResourceGroupName-Name$storageAccountName
$storageAccountKeys=Get-AzStorageAccountKey-ResourceGroupName$ResourceGroupName-Name$storageAccountName
$fileShare=Get-AzStorageShare-Context$storageAccount.Context |其中对象{
$\.Name-eq$fileShareName-和$\.IsSnapshot-eq$false
}
如果($fileShare-eq$null){
抛出[System.Exception]::新建(“未找到Azure文件共享”)
}
#指定给New-PSDrive cmdlet的根参数的值是存储帐户的主机地址,
#.file.core.windows.net用于Azure公共区域$fileShare.StorageUri.PrimaryUri.Host为
#之所以使用此选项,是因为非公共Azure区域(如主权云或Azure堆栈部署)将具有不同的
#Azure文件共享(和其他存储资源)的主机。
$password=ConvertTo SecureString-String$storageAccountKeys[0]。Value-AsPlainText-Force
$credential=New Object System.Management.Automation.PSCredential-ArgumentList“AZURE\$($storageAccount.StorageAccountName)”,$password
新PSDrive-Name-PSProvider文件系统-Root“\\$($fileShare.StorageUri.PrimaryUri.Host)\$($fileShare.Name)”-Credential$Credential-Persist

从那一刻起,你可以用任何你认为合适的方式驾驶。例如,通过使用
System.IO.File.ReadAllText
和{所需的驱动器号}.

可能最容易将unc驱动器作为本地驱动器安装

您可以装载到文件共享。将凭据放入配置中。 将脚本作为服务的一部分运行。 确保脚本运行

示例脚本:

$resourceGroupName = "<your-resource-group-name>"
$storageAccountName = "<your-storage-account-name>"
$fileShareName = "<your-file-share-name>"

# These commands require you to be logged into your Azure account, run Login-AzAccount if you haven't
# already logged in.
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$storageAccountKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName
$fileShare = Get-AzStorageShare -Context $storageAccount.Context | Where-Object { 
    $_.Name -eq $fileShareName -and $_.IsSnapshot -eq $false
}

if ($fileShare -eq $null) {
    throw [System.Exception]::new("Azure file share not found")
}

# The value given to the root parameter of the New-PSDrive cmdlet is the host address for the storage account, 
# <storage-account>.file.core.windows.net for Azure Public Regions. $fileShare.StorageUri.PrimaryUri.Host is 
# used because non-Public Azure regions, such as sovereign clouds or Azure Stack deployments, will have different 
# hosts for Azure file shares (and other storage resources).
$password = ConvertTo-SecureString -String $storageAccountKeys[0].Value -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList "AZURE\$($storageAccount.StorageAccountName)", $password
New-PSDrive -Name <desired-drive-letter> -PSProvider FileSystem -Root "\\$($fileShare.StorageUri.PrimaryUri.Host)\$($fileShare.Name)" -Credential $credential -Persist
$resourceGroupName=“”
$storageAccountName=“”
$fileShareName=“”
#这些命令要求您登录Azure帐户,如果尚未登录,请运行登录AzaAccount
#已登录。
$storageAccount=Get-AzStorageAccount-ResourceGroupName$ResourceGroupName-Name$storageAccountName
$storageAccountKeys=Get-AzStorageAccountKey-ResourceGroupName$ResourceGroupName-Name$storageAccountName
$fileShare=Get-AzStorageShare-Context$storageAccount.Context |其中对象{
$\.Name-eq$fileShareName-和$\.IsSnapshot-eq$false
}
如果($fileShare-eq$null){
抛出[System.Exception]::新建(“未找到Azure文件共享”)
}
#指定给New-PSDrive cmdlet的根参数的值是存储帐户的主机地址,
#.file.core.windows.net用于Azure公共区域$fileShare.StorageUri.PrimaryUri.Host为
#之所以使用此选项,是因为非公共Azure区域(如主权云或Azure堆栈部署)将具有不同的
#Azure文件共享(和其他存储资源)的主机。
$password=ConvertTo SecureString-String$storageAccountKeys[0]。Value-AsPlainText-Force
$credential=New Object System.Management.Automation.PSCredential-ArgumentList“AZURE\$($storageAccount.StorageAccountName)”,$password
新PSDrive-Name-PSProvider文件系统-Root“\\$($fileShare.StorageUri.PrimaryUri.Host)\$($fileShare.Name)”-Credential$Credential-Persist

从那一刻起,你可以用任何你认为合适的方式驾驶。例如,通过使用
System.IO.File.ReadAllText
和{所需的驱动器号}.

添加上下文:我们使用SDK使用azure文件共享,直到另一端的软件因某种原因无法与之连接,他们不得不使用更传统的网络驱动器。添加上下文:我们使用SDK使用azure文件共享,直到另一端的软件因某种原因无法与之连接,他们才使用SDK必须使用更传统的网络驱动器。