File Upload/Download Network Root Directory - asp.net-mvc

Using ASP.Net MVC - AdoDB
Im used to upload and download from inside the webserver where I published my files
Server.MapPath("~/UploadedFiles/pdfDocuments/");
and it worked fine.
But now, I want to send them to another root outside the webserver, inside a network directory(shared folder). Need your help because I already tried this:
Server.MapPath(#"\\sharedfolder\UploadedFiles\pdfDocuments\");
Please help me on this. Ill appreciate.

I think you no longer need Server.MapPath at all. Its purpose is to map a relative / virtual path (e.g. an incomplete path such as ~/UploadedFiles/pdfDocuments/ into a full path to a file on disk, e.g. that string might get converted into C:\inetpub\wwwwroot\UploadedFiles\pdfDocuments, for example.
Since you are now using a UNC path (i.e. a path in the form \\server\share), this is already a fully qualified path to a resource. There is no missing information. Therefore in this situation MapPath has no purpose. You can simply remove the line which uses MapPath from your code, and pass your UNC path directly to your upload/download code.

Server.MapPath only works on relative and virtual paths. https://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx
If that is a valid path from you server us it directly.

Related

Unrecognized property 'CommType' in connection string using Advantage Data Provider with Entity Framework

I'm trying to set CommType in connection string for Advantage DataBase Server using Entity Framework 5 and Advantage Data Provider in a .NET Web Application.
Connection string is in properties.config file.
I trie to use ads.ini but I don't know where to put it (I try in wwwroot/site/bin but nothing happened)
I need to set this parameters:
RETRY_ADS_CONNECTS = 5
PACKET_SIZE=512
USE_TCP_IP = 1
I can do this whiteout errors, but not using properties.config file.
AdsConnection conn = new AdsConnection("data source=\\\\SERVER1\\DATA; ServerType=remote;TableType=CDX;CommType = TCP_IP");
Any clue about how to solve this? Using ADS.INI or properties.config file, same for me.
Thank you!
Gaston Brave.
You can use the ADS.INI file for this purpose. Where it needs to be located (or how to tell Advantage where to find it) depends on the OS you're using.
From the Advantage Help file topic ADS.INI:
Windows
In order for the ads.ini file to be used, it must be located in the application directory, the Windows directory, the Windows System directory, or the client's search path.
In addition, if an environment variable exists with the name adsini_path, that path will be used to locate the ads.ini file. This can be helpful when you do not want to modify the application’s search path, but still need the ads.ini file to exist in a directory multiple users have rights to (for example on Windows Vista installations). An application can often set the environment variable at run-time before calling any Advantage functions, which avoids the need to set a per-workstation environment variable.
Linux
In order for the ads.ini file to be used, it must be located in the application directory, a directory specified in an environment variable named ADSPATH, in the users home directory, or in the /etc directory. If located in the users home directory the ads.ini file should be named .ads.ini (note the initial "dot").

MAMP/WAMP - Switch back from real project URLs to localhost in all my files

Good morning,
does anyone know how I could configure MAMP (or WAMP) in order to automatically change my project URLs, to localhost without having to search/replace inside my documents (operation I suppose to be a bit gross because possibly altering my code).
My goal is to develop on local while keeping the final and real URLs in my documents.I suppose lot of you have encountered this issue one day :)
In other word, I would like to alternate between online and local more easily.
I a beginner, please consider,
for all the biginners, here's the thing. I've created a config.php file which contains constants: one config file for the local project folder and one for the online server folder.
Inside this config file, I've create a constant (constant are then available everywhere in the project) to define the main URL of the project. e.g.:
define('CST_MAIN_URL',http://www.myproject.com); // for the online config.php file
define('CST_MAIN_URL',http://localhost:8888); // for the local config.php file
Thus, each header or redirection can work with that constant, like:
header('location:' . CST_MAIN_URL . 'index.php');
Then, things must have to do with RewriteEngine in your htaccess file, for instance whenever you must modify the behavior of MAMP/WAMP if an interrogation point or a slash provokes you with its malicious resistance. But, unfortunately RegEx expression must be understood as a basic level for mastering those url rewritings.
Hope it'll helps.

ASP.NET MVC How to display Image from folder outside webroot

Individual Folder create for each user when they register on website outside the webroot folder.I am able to upload the image and store Image path in database.However,I am unable to display the Image. I am trying to get the path of Image from database using LINQ and display in VIEW but it does not work. I can view only one(from the list of Image)Image when FILESTREAM the image path and retrun using FILESTREAMRESULT
Can anyone please guide me how to achieve it? All I want to do is create folder for each respective user when they register in external folder. Upload Image and display.
Typically, I would keep files in a secure database or within the application's subfolders. But, here's what I would suggest if you really need to access a different folder on the server.
Create a folder on your server's file system ahead of time.
On the server, assign permissions to that folder so that the identity used by your application can access it.
In your code, write code to access the folder and file path.
Hope that helps!
p.s. here's another Q&A on StackOverflow (with some words of warning) in which the second part of the answer is similar to what I suggested.
ASP.NET - Reading and writing to the file-system, outside the application

save path in database / or \

I want to save the path of an image in my database. I'm developing on a Windows system.
I'm using
setDestination( APPLICATION_PATH . "/userfiles/")
In my database I have a path like the following:
C:\wamp\www\cheyenne\application/userfiles\test...
If I try to use a relative path like \public\covers I get an error like "path or directory does not exist".
I'd prefer the 2nd possibility because the former webserver will be an Apache on a Linux.
It's not a good idea to store in a database the complete path of your picture. You really should consider to use a relative path and build the complete path on render, with a database view... My point of view is that you can or not know where your application will be and how your application will be deploy.
For example, today, you store your image on the same server, tomorow, because of traffic issues, you move all your pictures on a second server dedicated for pictures... if you store the complete path of your pictures, you have to execute a SQL request to change partial path and update your code. If you have juste a relative path, you just have to change your application configuration. This can be done in a config.local file that override your default configuration.
For the backslash... it's normal, you are on Windows. Use on your code the default php global variable DIRECTORY_SEPARATOR instead of "/".

IHttpModule not being applied to virtual directory

I have a network folder that is mapped to my iis app as a virtual directory and I'm trying to do some authentication for files that are located there with an ihttpmodule. I've verified that the ihttpmodule is firing properly for anything else in my app, just not the files located in virtual directory. Most of what I've found is that the directory can't be listed as an application (which it isn't), and everything should work. The other solution that I found was to add the the module tag to the tag, but that didn't seem to help either. Everything that I've found talks about stopping this from happening. So my question is what could be set that is causing this to not work? Is there a certain execute permission that needs to be set? Any other iis settings that could cause this? It is an mvc app, and this is how my directory structure is laid out:
server/app <- my application folder
server/app/content/downloads <- downloads is the virtual directory
Do I have to add the virtual directory directly under my app directory? Is that part of the problem? I don't have direct control of the server my code is running on, so testing things out is a bit of a pain... so I was looking for some more thoughts before starting to send emails off to my operations people. Thanks!
Well, I think I found what the issue is.... it looks like by default, iis6 does not pass executables, zip files, or anything of that nature through the .net runtime. It only does that with .aspx files and such, so it will never fire my ihttpmodule. It looks like you can force it to by adding a mapping for that extension, but is there a code work around for this? Or is that the only way?

Resources