简体   繁体   中英

On ASP hosting, get physical path to App_Data (for SQLite database access)

I'm trying to get the physical path to the App_Data folder, but I keep getting a local network\\IP address, like:

\\192.168.0.100\localuser\myappname\App_Data\

This address seems to work for simple IO.File, like writing to a text file. This doesn't seem to work for SQLite databases, which is what I really need to get working.

So, my question is:

  • Can I use this network address for SQLite access? If so, how?
  • OR, how do I get the real physical path, like for example "C:\\blabla\\App_Data".

I'm using the following code:

Hosting.HostingEnvironment.MapPath("~") & "App_Data\"

NB: I'm familiar with VB.NET and C#, so code examples may be either one.

You are getting this path because the IIS site is pointing to it. Your provider or administrator has set it up that way, and you can't change it without reconfiguring IIS.

There's nothing wrong with using the path just as it is.

BUT your code should read

Hosting.HostingEnvironment.MapPath("~/App_Data")

You don't ever want to use "&" (string append) for building paths. Let the framework do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM