I have a web application deployed over two load balanced servers, Out of which one acts as a repository of all images used for application. Path similar to below exists on say "webserver1"
C:\inetpub\Images\
Images folder is shared with "EveryOne" permission to FullControl.
Now on "webserver2" , I add a virtual directory which points to "\webserver1\Images"
This can be accessed as expected using windows+r on webserver 2.
Although in My application which hosted on webserver2 IIS.
I get error which say "File not found \webserver\images\filename"
I believe the permissions should be already taken care of by assigning Everyone?
Can someone help?
UPDATE:
Code used to read file from webserver2 is
Server.MapPath(filename)
filename is \images\filename which transforms to \webserver1\images\filename
and throws file not found error
Exception after putting some variables in exception throw:
mappath is \Webserver2\ProductImages.. filename is /images/ProductImages/..
Exception thrown is "\Webserver2\ProductImages.." file not found IO Exception
Related
We have a wcf service that uses DevExpress XtraReports to generate a pdf file.
How this normally works is we have in the web.config the physical directory Example C:\PdfDocs\ that we specify as the path when executing the devexpress ExportToPdf function. This works fine on a normal virtual machine.
We are now busy moving to Microsoft Azure enviroment and I am having trouble getting this to work.
My Setup - The wcf service is created as a App Service. Unfortunately I am not at liberty to give names so lets assume the following:
App Service Name - testdocservice,
Url Azure gives - https://testdocservices.azurewebsites.net
What I have tried:
In Application settings, I have created a virtual directory. In the project itself I have created a folder that the virtual directory will point to.
The virtual path is https://testdocservices.azurewebsites.net/ItinDocs and the physical path is site\wwwroot\ItinDocuments
This is setup correctly as I have tested it by FTP test pdf in and then hit the following url: https://testdocservices.azurewebsites.net/ItinDocs/test.pdf
So in the wcf service I took a chance and set the location to render the pdf to "site\wwwroot\ItinDocuments" - This did not work.
The exception was as follows: Access to the path 'D:\Windows\system32\site\wwwroot\ItinDocuments\TestQuote21.pdf' is denied.
I then tried using Server.MapPath example:
QuoteV3 oQuote = new QuoteV3();
oQuote.DataSource = dSource;
oQuote.ExportToPdf(System.Web.HttpContext.Current.Server.MapPath($"~{ConfigurationManager.AppSettings["DocLocation"]}{fileName}"));
The DocLocation look like the following: site\wwwroot\ItinDocuments\
This also did not work. The following error is given:
'~https:/testdocservices.azurewebsites.net/ItinDocs/TestQuote21.pdf' is not a valid virtual path.
I thought the first character "~" could be a problem so I removed it and got the same error as above - 'https:/testdocservices.azurewebsites.net/ItinDocs/TravelQuote21.pdf' is not a valid virtual path.
I then noticed that the above errors only have one forward-slash after the https. At this point I am not sure if that could be causing the problem and then how to correct it as the Server.MapPath is generating that part.
In conclusion, I am not sure if I am even working in the right direction with the above approach. My knowledge around azure is still minimal.
Any help/assistance/solution would be greatly appreciated.
Many thanks.
This can be closed as I have instead setup azure storage and my pdfs are saving in a container instead.
Thanks.
I have a web service that is trying to write a file to a file share.
The application pool for the site in iis is running as a custom domain account: "domain\domainaccount"
I'm operating under the assumption and hope that when the code tries to write the file it will use the "domain\domainaccount" user to do so.
Executing the following line of code produces the error: Access to the path [filename] is denied
FileStream stream = File.Create(fileName, result.Length);
I have confirmed that the "domain\domainaccount" account has access to [filename] which is the full path of the file including the file name. I have even given the account access from the very top of the share structure, not just the specific folder the file needs to be written to. In fact, if I run notepad as "domain\domainaccount" I can save a file to that exact location.
What might I be doing incorrectly? Is it not using the domain account to write the file? If not, can I change something so that it does?
I should note that if I log into the iis server and run the web service from there, I do not get the access denied message and the file is created.
I am developing a Windows Phone 8 application but am having a lot of issues with file access permission exceptions hindering the approval of my application when ever I try accessing files in the "local" folder (this only happens after the application has been signed by the WP store, not when deployed from Visual Studio). To solve this I have moved all file operations to IsolatedStorage and this seems to have fixed the problems.
I only have one problem left though. My application needs to make use of the file extension system to open external files and this seems to involve the file first being copied to the local folder where after I can then manually copy it into IsolatedStorage. I have no problem in implementing this but it seems that a file access permission exception also occurs once the system tries to copy the external file into the local folder.
The only way I think this can be solved is if I can direct the system to directly copy into IsolatedStorage but I cannot figure how to do this or if it is even possible. It seems as if though the SharedStorageAccessManager can only copy into a StorageFolder instance but I have no idea how to create one that is directed into IsolatedStorage, any ideas?
PS. Do you think that the Microsoft system might be signing my application with some incompetent certificate or something because there is not a hint of trouble when I deploy the application from Visual Studio, it only happens when Microsoft tests it or when I install it from the store using the Beta submission method.
Below is a screenshot of the catched exception being displayed in a messagebox upon trying to open a file from an email:
EDIT:
Just to make it even clearer, I do NOT need assistance in figuring out the normal practice of using a deep link uri to copy an external file into my application directory. I need help in either copying it directly into isolatedstorage or resolving the file access exception.
Listening for a file launch
When your app is launched to handle a particular file type, a deep link URI is used to take the user to your app. Within the URI, the FileTypeAssociation string designates that the source of the URI is a file association and the fileToken parameter contains the file token.
For example, the following code shows a deep link URI from a file association.
/FileTypeAssociation?fileToken=89819279-4fe0-4531-9f57-d633f0949a19
Upon launch, map the incoming deep link URI to an app page that can handle the file
// Get the file token from the URI
// (This is easiest done from a UriMapper that you implement based on UriMapperBase)
// ...
// Get the file name.
string incomingFileName = SharedStorageAccessManager.GetSharedFileName(fileID);
// You will then use the file name you got to copy it into your local folder with
// See: http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.storage.sharedaccess.sharedstorageaccessmanager.copysharedfileasync(v=vs.105).aspx
SharedStorageAccessManager.CopySharedFileAsync(...)
I've inline the information on how to do this from MSDN http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987(v=vs.105).aspx
Read that documentation and it should be clear how to use the APIs as well as how to setup your URI mapper.
Good luck :)
Ok I figured it out. The "install" directory is actually restricted access but for some reason the Visual Studio signing process leaves the app with enough permissions to access this folder. The correct procedure of determining a relative directory is not to use "Directory.GetCurrentDirectory()" but rather to use "ApplicationData.Current.LocalFolder". Hope this helps!
What I am trying to accomplish is to upload some files from one domain on my shared hosting to another domain on the same hosting where the files will be displayed. When I debug the application, the process gets to the SaveAs() method and then throws the exception,"Could not find a part of the path ..." .
I have followed these instructions on finding my site's folder's absolute path and I have implemented this path in my code, using the same method I've been using for a good part of my file uploading, and I have never ran into any problems. My read/write permissions are allowed for the folder that I'm attempting to save these files in.
I'm wondering "Is it because I'm trying to upload the file to a different directory?". If so, is there a better way to accomplish this?
var fileName = Path.GetFileName(file.FileName);
var path = #"D:\Hosting\someNumbers\html\SiteFile\SiteImages\" + fileName;
file.SaveAs(path);
myObject.FilePath1 = path;
Any help will be highly appreciated.
As it turns out, my error was more or less a security issue with GoDaddy's hosting. GoDaddy sees this type of action as a "third party FTP request", which is not allowed. In conclusion, GoDaddy does not allow a user to upload a file on one site, and then FTP that file to another site on the same hosting plan.
I am having a hard time on this one, I have a folder over the network with public access (no credential restriction). I am trying to do a File.Exist or Directory.Exist and I keep on having a exception.
Can someone tell me the good way to do IO over the network.
EDIT 1 FOR DETAILS:
if i do execture => \agoodip\Public\test.txt I get the file etc etc
In my code it look like a basic
Directory.Exist(#"\\agoodip\Public") or
File.exist(#"\\agoodip\Public\test.txt")
The exception I get is Path not found.
EDIT 2 :
I am using Silverlight 3, Is there any security pattern to be aware of to lookup file on the network?
Thanks!
I don't believe that is going to work for you. Silverlight doesn't allow arbitrary access to the file system or shares. Silverlight runs within a sandbox environment so you have restricted access to the file system.
You need to begin your UNC path with two backslashes ("\\") if it refers to a network path rather than a local path.