Server.MapPath 有一个大问题,因为我无法从服务器解决它。 我在文件夹中获取证书文件,在本地,它以各种不同的方式工作正常,但是当我将其放到服务器上时,它显示错误“找不到指定的文件路径”
.aspx.cs 文件中的 MyCode:
var certificatePath = HttpContext.Current.Server.MapPath("~/Push/testkeys/Certificates.p12");
var Push = new PushNotification(true,certificatePath,“移动”);
.cs 文件:
public PushNotification(bool useSandbox, string p12File, string p12FilePassword)
{
if (useSandbox)
{
_host = SandboxHost;
_feedbackHost = SandboxFeedbackHost;
}
else
{
_host = ProductionHost;
_feedbackHost = ProductionFeedbackHost;
}
_certificate = new X509Certificate2(p12File, p12FilePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
_certificates = new System.Security.Cryptography.X509Certificates.X509CertificateCollection { _certificate };
// Loading Apple error response list.
_errorList.Add(0, "No errors encountered");
_errorList.Add(1, "Processing error");
_errorList.Add(2, "Missing device token");
_errorList.Add(3, "Missing topic");
_errorList.Add(4, "Missing payload");
_errorList.Add(5, "Invalid token size");
_errorList.Add(6, "Invalid topic size");
_errorList.Add(7, "Invalid payload size");
_errorList.Add(8, "Invalid token");
_errorList.Add(255, "None (unknown)");
}
我的代码在我的本地计算机上运行得很好。 Server.Mappath 读取目录中的文件,然后页面上的 Gridview 会填充文件的名称,如底部的 gridview 所示。底部是一个显示路径文件夹文本的标签。所以 Server.Mappath 正在使用这个路径并查看这些文件。但不在实时服务器上。该页面没有任何网格视图。所有文件都在文件夹中。有人对可能出现的问题有什么建议吗?我尝试在 /users 前面放一个 ~ 所以 ~/users ,但这没有帮助。
Private Sub BindGridview()
Dim pathtofolder As String = "/users/" & Session("lastname") & Session("SSNLast4") & "/forms/"
Dim filePaths As String() = Directory.GetFiles(Server.MapPath(pathtofolder))
filePaths = Directory.GetFiles(Server.MapPath(pathtofolder))
Dim files As List(Of ListItem) = New List(Of ListItem)()
files = New List(Of ListItem)()
lblpath.Text = pathtofolder
For Each filePath As String In filePaths
files.Add(New ListItem(Path.GetFileName(filePath), filePath))
Next
GridView2.DataSource = files
GridView2.DataBind()
End Sub