We host C# 3.5 net web app in ISS 7.5.
PDF files are generated and put in some directory. Listing of directory is disabled. With all browsers (IE10, FF, Opera...) we can access the PDF.
When accessing the URL with Chrome, PDF is loaded... then we get a 403 error. If we disable chrome internal pdf viewer and tell it to use Adobe's, it works fine.
What can be wrong?
Problem is explained here: http://productforums.google.com/forum/#!topic/chrome/1mSjCjabwPE
But the mentioned KB cannot be applied so we'll do with some HttpHandler.
public void ProcessRequest(HttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
if (!context.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
return;
}
string requestedFile = context.Server.MapPath(context.Request.FilePath);
context.Response.ContentType = "application/pdf";
context.Response.TransmitFile(context.Server.MapPath(context.Request.FilePath));
context.Response.End();
break;
}
}
Related
I'm trying to disable the pdf viewer in a new tab when I use chromium in Playwright. Do you know how can achieve that? Firefox has a method, it's called .setFirefoxUserPrefs().
For chrome, it's not implemented, but found the following thing:
chrome://settings/content/pdfDocuments +++ accessible by playwright.
How it can be implemented?
I tried to take know-how from selenium, but for the playwright, it just doesn't work.
I tried:
how to disable chrome pdf viewer in selenium and it should auto download in the default downloads when any pdf occurs
Disabling PDF Viewer plugin in chromedriver
but without any success, can you support me with that?
Including, I tried that:
private void PlaywrightSmokeTestConfigureInit(String browserType) {
playwright = Playwright.create();
ArrayList<String> arguments = new ArrayList<>();
arguments.add("--start-fullscreen");
boolean headless = false;
Map<String, Object> map = new HashMap<String, Object>();
map.put("pdfjs.disabled", true);
map.put("pdfjs.enabledCache.state", false);
map.put("plugins.plugins_disabled", new String[] { "Chrome PDF Viewer" });
map.put("plugins.always_open_pdf_externally", true);
map.put("profile.default_content_settings.popups", 0);
map.put("safebrowsing.enabled", "true");
switch (browserType) {
case "chromium":
browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel(browserType).setHeadless(headless).setArgs(arguments)
.setFirefoxUserPrefs(map));
break;
case "firefox":
browser = playwright.firefox().launch(new BrowserType.LaunchOptions().setChannel(browserType).setHeadless(headless).setArgs(arguments));
break; ...
I support a web application on an intranet which has a word icon the user can click which will then retrieve bytes from a SQL server and then open Microsoft Word to display the document.
While this works well, our organisation is moving from IE to Chrome, and this doesn't work in Chrome, and from what I have heard Chrome doesn't support ActiveX which is what is used to open Microsoft Word.
So we are looking for a solution that will work in Chrome.
A quick example of what we do.
Javascript fired by onclick event
var wordObject = new ActiveXObject("Word.Application");
wordObject.Documents.open('http://localhost:8080/Document/Download/MyDocument.docx?documentId=12345');
wordObject.Visible = true;
Action in Controller
[HttpGet]
public ActionResult Download(int documentId)
{
var result = DocumentService.GetLatestDocumentVersion(documentId);
if (!result.Succeeded)
{
return HttpNotFound();
}
return new DocumentResult(result.Data.FileData, result.Data.FileType, result.Data.FullName);
}
public class DocumentResult : FileContentResult
{
private ContentDisposition _contentDisposition;
public DocumentResult (byte[] fileContents, FileType fileType, string fileDownloadName)
: base(fileContents, fileType.ToMimeType())
{
string disposition = fileType == FileType.Pdf ? DispositionTypeNames.Inline : DispositionTypeNames.Attachment;
_contentDisposition = new ContentDisposition(disposition);
_contentDisposition.FileName = fileDownloadName;
}
}
I want the same functionality but in Chrome, any ideas?
So instead of opening word through javascript you simply replace the url with something like
Document
This uses office uri schemas see https://learn.microsoft.com/en-us/office/client-developer/office-uri-schemes?redirectedfrom=MSDN
Thanks to MS Premier Support.
I'm using the following when trying to open a local file:
some document
When I click the above in a browser, it opens Finder to the folder. But does not open the file. Should I be doing something else to have the file open in Numbers?
You cannot open local files on the client. This would be a huge security risk.
You can link to files on your server (like you did) or you can ask the client for a file using <input type="file">
You can only open some types of files in browsers, like html css js and mp4, otherwise the browser will want to download it. Also remember that browsers replace spaces with %20. I recommend right clicking the file and opening it with chrome then copy that link and using it.
You can open files that are local as long as it is a file that is on the file that is trying to open another file is local.
Your issue is likely the space in the document name. Try this instead:
some document
The %20 will be read by your browser as a space.
Update
The other answer points out something I missed. The .numbers extension will not be able to be opened directly by your browser. Additionally the other answer describes the security risk this could create.
The File API in HTML 5 now allows you to work with local files directly from JS (after basic user interaction in selecting the file(s), for security).
From the Mozilla File API docs:
"The File interface provides information about files and allows JavaScript in a web page to access their content.
File objects are generally retrieved from a FileList object returned as a result of a user selecting files using the <input> element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement."
For more info and code examples, see the sample demo linked from the same article.
This might not be what you're trying to do, but someone out there may find it helpful:
If you want to share a link (by email for example) to a network file you can do so like this:
file:///Volumes/SomeNetworkFolder/Path/To/file.html
This however also requires that the recipient connects to the network folder in finder --- in menu bar,
Go > Connect to Server
enter server address (e.g. file.yourdomain.com - "SomeNetworkFolder" will be inside this directory) and click Connect. Now the link above should work.
Here is the alternative way to download local file by client side and server side effort:
<a onclick='fileClick(this)' href="file://C:/path/to/file/file.html"/>
js:
function fileClick(a) {
var linkTag = a.href;
var substring = "file:///";
if (linkTag.includes(substring)) {
var url = '/v/downloadLocalfile?path=' +
encodeURIComponent(linkTag);
fileOpen(url);
}
else {
window.open(linkTag, '_blank');
}
}
function fileOpen(url) {
$.ajax({
url: url,
complete: function (jqxhr, txt_status) {
console.log("Complete: [ " + txt_status + " ] " + jqxhr);
if (txt_status == 'success') {
window.open(url, '_self');
}
else {
alert("File not found[404]!");
}
// }
}
});
}
Server side[java]:
#GetMapping("/v/downloadLocalfile")
public void downloadLocalfile(#RequestParam String path, HttpServletResponse
response) throws IOException, JRException {
try {
String nPath = path.replace("file:///", "").trim();
File file = new File(nPath);
String fileName = file.getName();
response.setHeader("Content-Disposition", "attachment;filename=" +
fileName);
if (file.exists()) {
FileInputStream in = new FileInputStream(file);
response.setStatus(200);
OutputStream out = response.getOutputStream();
byte[] buffer = new byte[1024];
int numBytesRead;
while ((numBytesRead = in.read(buffer)) > 0) {
out.write(buffer, 0, numBytesRead);
}
// out.flush();
in.close();
out.close();
}
else {
response.setStatus(404);
}
} catch (Exception ex) {
logger.error(ex.getLocalizedMessage());
}
return;
}
You can expose your entire file system in your browser by using an http server.
caddy2 server
caddy file-server --listen :2022 --browse --root /
serves the root file system at http://localhost:2022/
python3 built-in server
python3 -m http.server
serves current dir on http://localhost:8000/
python2 built-in server
python3 -m SimpleHTTPServer
serves current dir on http://localhost:8000/
This s
I've got a css file injected into my asp.net web form application page through a base page. The method I use look like the following:
private void InjectLocalStyleSheet()
{
if (this.Page.Header == null)
return;
Literal cssFile = new Literal()
{
Text =
#"<link rel=""stylesheet"" type=""text/css"" href=""" + Page.ResolveUrl("~/Common/Theme.css") +
#""" />"
};
Page.Header.Controls.Add(cssFile);
}
When I run the page in firefox, that css file gives me a 302 warning. Apparently, firefox view this file as html type while I've specified the type to be "text/css".
snap of request and response headers
I also run the web page in Chrome and get "Failed to load resouce: net::ERR_TOO_MANY_REDIRECTS"
Anyone has an idea about what is going on? Please help. Thank you.
I uploaded my project in IIS which was working fine in local but in windows server 2008 R2 it was showing the above attached issue after login(Please check the attached image). The above issue was coming because Internet Explorer Enhanced Security Configuration(IEESC) was on, so I make it off but still my page was not working.
Page Behavior: 1) No page error .Also no 404 and 403 error.(Even if CustomError mode is On)
2) Controls including grid view was not getting filled up from database by JSON call.
Solution: 1) Enable .json file extension simply follow this instructions. Open the properties for the server in IIS Manager and click MIME Types
Click "New". Enter "JSON" for the extension and "application/json" for the MIME type.
2) Add the following line in web.config file
3) If you deploy your application to IIS your URI must include your application name as well. So, as your application name is QCValueStream, then your URI must be http://localhost/QCValueStream/ManageProjects/GetManageProjectsData/5.
You can automatically detect your base Uri and have it prepend by adding a line in your master page(Asp.net web application) or shared _Layout.cshtml(Asp.net MVC):
<script type="text/javascript">
var config = {
contextPath: '#Url.Content("~")'
}
var baseUri = config.contextPath;
//or
var baseUri = '#Url.Content("~")';
//Then in your JS you prepend by:
//Incorrect JSON Call
$.getJSON('/ManageProjects/GetManageProjectsData?', { searchText: inputsearchText }, function (data) {
myData = data;
});
//Correct JSON Call
$.getJSON(baseUri +'/ManageProjects/GetManageProjectsData?', { searchText: inputsearchText }, function (data) {
myData = data;
});
</script>
Note: Check the below url to make off Explorer Enhanced Security Configuration for Administrator or user.
http://www.aurelp.com/2013/01/16/how-to-turn-off-internet-explorer-enhanced-security-configuration-step-by-step/