this works on dev as usual when I put it on UAT the code does something different. A PDF is saved on the server, the class then opens it up using the url of that file.
The URL works fine if I paste it into a browser, but doesn't work from the code.
Here's my code:
Process.Start(openPath);
openPath will look like: "http://www.cbm360.net/test/temp/CBM360Report_1093750.pdf"
The file is there on the server, but it just won't open in the code.
The code is inside a web method called using AJAX, if that makes any difference, I'm not sure.
Does anyone have any suggestions as to why this isn't working?
The Exception is:
System.ComponentModel.Win32Exception: The system cannot find the file specified
Thanks!
Instead of pasting the URL into a browser (I assume this is on the server), try it directly from the command line on the server. Does it work now? Process.Start is not the same as navigating to a URL in the browser, it is more akin to running the URL from the command line. I am not sure what you are trying to achieve. Normally we would use a web request to get a pdf.
Related
I have a blazor server app (.net 6) that worked fine locally. I needed to load a configuration file for the Ebay api, so it is a YAML file kept in the structure of my project.
On the server I can hard code access to it with the following path and the site works perfectly:
$"D:/home/site/wwwroot/Config/ebay-config.yaml"
However, when I try to get the exact same result using the relative path method for blazor server I am screwing it up somehow.
$"wwwroot/Config/ebay-config.yaml"
That was the first thing I found and tried. It gives me an error that it can't find $"D:/home/site/wwwroot/wwwroot/Config/ebay-config.yaml". Clearly the relative file path works to an extent, but for some reason wwwroot is put in there twice and it fails.
Using $"{env.WebRootPath}/Config/ebay-config.yaml" gave a similar result, with two wwwroots.
Can someone please tell me what the correct method to use to get to the wwwroot folder from the web server? It is currently hosted on Azure if that matters.
Thanks in advance.
Just in case anyone else comes looking...
Per the comment from Lex I went back and looked at it again. Using the file locationg like this works on both localhost and azure server.
$"Config/ebay-config.yaml"
I am working on a system that has a WPF WebBrowser that is displaying dynamically generated HTML.
This contains links to files, using file:///servername/filename.ext addresses.
This should have worked in times gone by when this was first developed, but does not seem to behave now.
What I can see:
White click on the generated file in the browser of being an HTML file: File is served from about:blank and in the Internet Zone. Clicking a link does nothing.
What I have done:
I have added about:blank to the Trusted Zone, and have set the security for the Trusted Zone to Low. Clicking a link still does nothing.
Created an HTML file and hosted it on my local IIS. Browse to this file in IE. The file contains a link to a file:/// address. Nothing happens on click.
Added http://127.0.0.1 to the Trusted Zone. The above test still fails.
Changed the generated HTML to be a link to http://www.google.com. This works.
What I think is happening:
The WPF WebBrowser is IE underneath. Did IE have a security update that stopped access to file:/// paths?
What I cannot do due to technical restrictions with deployment:
Have the generated HTML and the files linked to served by a web server so everything is within an http(s) environment.
What I can do:
Update browser settings
Update our code
Update - additional information:
The HTML is being displayed on the WPF by binding to a string that contains the HTML (effectively <html><body>Look! Stuff!<br />Whatever</html>)
file:///foo/whatever.txt exists and I have access to it
That file is generated by a process on a server and the client is generating the link to the file. This is a historic design, I didn't come up with it, I'm just maintaining it. I can't do massive code overhauls.
I cannot install any additional services anywhere
All Browsers have updated to prevent interesting stuff happening on local HTML files. Because you could do interesting stuff in the past it meant interesting exploits could be utilized too.
I've had a recent issue where I created a HTML in code and wanted to display it in CEFSharp (much better than WebBrowser by the way) with a link to CSS and JavaScript Files.
How I fixed it was to run a LocalHost and did this using this code which works really well: An HTTP file server (130 lines of code) in VB.Net
For testing your HTML outside of code you could run this batch file to start your LocalHost:
ECHO OFF
ECHO "Launching Localhost:8080"
py -3 -m http.server
ECHO "Loading HTML.."
start chrome localhost:8000
This batch file assumes you have Python 3+ installed. You can verify this in the Command Prompt with:
python --version
I've solved this by cheating a little.
I've got the VM to write the HTML out to a file, and then pass the file name to the browser in the view. This means that I am displaying the created content from file:////foo.htm, and that is fine for links to file:///server/bar
I have a jQuery script in which I want to download a file which is located on some server after the user clicks on the link. On IE11 this works alright, as I simply make a call to:
window.open('file:///MyServer0001/SomeFolder/Tmp/ToiletFlush.log'
I know that for security reasons, Chrome doesn't allow to use the protocol file:/// . It is interesting because if I write myself this URL on the address bar he will show the file, however if I make a call for window.open() he just opens me a new empty window. Also, removing the file:/// , doesn't do anything on Chrome, it says that the page is not available
So right now I don't know how to make this work on chromium. I thought I could make a workaround by calling the controller function through a POST/GET , return a FileResult and download the file. This definitely works but I would like to know a simple way to do this directly only using jQuery/JavaScript.
Any Idea?
Try ASP.NET MVC FileResult:
View:
Download File
In Home Controller:
public FileResult GetFile()
{
//Read file content into variable.
string content=File.ReadAllText("filepath");
byte[] byteArray = Encoding.ASCII.GetBytes(content);
return File(byteArray, System.Net.Mime.MediaTypeNames.Text.Plain, "ToiletFlush.log");
}
Try this,
On Windows:
1. Find the local URL of your Chrome Install
2. From the Command Line launch Chrome w/ '–allow-file-access-from-files' prepended to it:
–allow-file-access-from-files C://...
On OSX, just type this in Terminal:
open /Applications/Google\ Chrome.app --args --allow-file-access-from-files
Using Google Chrome Canary is also possible:
open /Applications/Google\ Chrome\ Canary.app --args --allow-file-access-from-files
Or... You'll need to run your application on a local server.
As I have been requested by my instructor to use AntiXss library in the development of my senior project, I am facing a lot of difficulties of using this library because of the lack of resources on the web. A part of my project I have an upload file function where the user will be able to upload files, and after uploading his files, he will be redirected to the same page to see some other information. Everything works fine, but when I added AntiXss library and use it with the following line only, I got this error
(HTTP 400 Error - Bad Request)
and I don't know why. Could anyone tell me why I am getting this error? And how to fix it?
C# Code:
Response.Redirect(Encoder.HtmlFormUrlEncode(Request.Url.PathAndQuery));
Break up your code and look at each step:
Take the incoming request's URL, and extract out the path and query.
Run that through a form-based encoder
Redirect to that string
What do you think a form-based encoder would do in order to prevent XSS attacks?
Try this:
Response.Write(Encoder.HtmlFormUrlEncode("http://www.stackoverflow.com"));
What is written out? Try putting that in a web browser, and you'll likely get a 400 (or a 502) error.
Request.Url.PathAndQuery
The above syntax returns `/Cambia3/Temp/Test.aspx?query=arg`
For further url references check this
HtmlFormUrlEncode gets string and encode as parameters. for further info on that see here
I'm building an application which involves writing some fields to a database, along with uploading some files from the end user to an FTP site. The file upload works fine... in IE. In Firefox and Chrome, I get an error that it can't find the file (running it in localhost at this point, haven't moved it to a dev or production environment yet).
I have tried getting the file via:
Server.MapPath(FileUpload1.PostedFile.Filename)
... which points to the folder the application is residing in.
And also:
Path.GetFullPath(FileUpload1.PostedFile.Filename)
... which points to c://Programs (x86)/... ...
I can get a file to upload properly if I get it from either folder, but nothing from anywhere else.
Any ideas on how to make this point to the right place? Or, will it actually work properly once it resides in a server environment?
Thanks in advance!
FileUpload.PostedFile.Filename works differently in each browser. in Firefox and Chrome it won't include the full path - just the file name. It depends on your customer's browser.
FileUpload.PostedFile.FileName
This actually gives you path of the uploaded file.
But in all the newer browsers (FF 3.6 series, Chrome, IE7+) this feature has been disabled due to security reasons. Any website should not need path of a file stored in client's systems because that gives the directory structure and may expose other important things to website owner.
So in your case, the above code returned only the file name.
you can check this link, it may help you Fileupload control - fullpath issue