Create a download link with Microsoft IIS - iis

I want to set up a direct download link using Microsoft IIS. We already have a web page using the IP address that points to a /web folder on our server, but I want to create a separate location on my server where I can put downloadable files such that the client can just type the link and get the download: http://IPADDR/download/filename.zip. Are there any resources on how to do this?
Right now, typing http://IPADDR brings up our simple web page which contains a link that launches an application, again this is bound to the /web folder on our server via IIS.
The FTP port is typically blocked on our client's networks so we have to stick with HTTP. This will be completely programmatic, so no need to have a button or link on a page. I will be using java with a GET command to pull files from the link. I just want to be able to have the web server make these files available to download.
FYI I'm newer to this server stuff so simpler is better! Thank you.

As far as I know, there are two ways to achieve your needs.
The first is using Asp.net application. You need to write code for the downloaded file. For example, when the user clicks a button, the logic method corresponding to the button is triggered, and the response to the client is the file specified in the code.
var fileNameToShow = "xxx.zip";
var fileNameAndPath = "The physical path of the file on the server"
FileInfo file = new FileInfo(fileNameAndPath);
file.Refresh();
if (file.Exists)
{
// Send the file to the browser
Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename= " + fileNameToShow + "; size=" + file.Length.ToString());
Response.TransmitFile(fileNameAndPath);
Response.Flush();
Response.End();
}
else
{
throw new Exception("File does not exist!");
}
The second is to use the FTP function of IIS. You need to create a site and add FTP publishing to the site. When you visit the site through ftp://domian, you can see all the files in the physical directory of the site on the server, and you can download any file by clicking on it.(It also can download through link,such as ftp://domain/filename.zip)

Related

Open document from share point directly in office365

I'm using the graph API to access the documents in SharePoint. The response I'm getting looks like this:
graph api response
I want to let the user open this file (an excel file in this example) using excel desktop app. In other words, I want to resemble in my app the "Open in desktop app" functionality Excel for the web already provides:
excel for the web functionality
Is that possible?
Thanks in advance!
You can try and get the webUrl of the parent folder of the document you want to open. On that webUrl you add:
String documentUrl = parentWebUrl + "/YourDocumentName.docx";
And then you use Office URI scheme to open it localy (read more here)
It should be possible to do it using the webUrl of the document itself, but i have not figured out how to do it.

Allow Powershell script download from webpage in IIS

I am trying to update a Razor page (running on IIS 10.0 version 1809) to allow me to share a Powershell script. I want the user to be able to right-click the link and select "save" to download the script from a folder on the web server (wwwroot/<site name>/downloadFiles). I verified that the NTFS permissions allow "Read & Execute", "List folder contents", and "Read" to IUSR, Network Service, Users, and IIS_IUSRS.
I tested:
Right-click the link and select "Save link as..." and Chrome tells me, "Failed - No file"
Browse to https://<site url>/<site name>/downloadFiles/script.ps1 and IIS tells me: 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
Browse to https://<site url>/<site name>/downloadFiles and IIS tells me: 403 - Forbidden: Access is denied. You do not have permission to view this directory or page using the credentials that you supplied.
In _Layout.cshtml, I have the link setup as:
Script
Any idea how I can make this work?
Use the FileExtensionContentTypeProvider to map the .ps1 extension to the application/octet-stream mime type to force a download as explained in the docs: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files#fileextensioncontenttypeprovider
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".ps1"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});

Net Core Razor Pages - Microsoft Identity Web Package after Sign-out is breaking website image links

This is very strange issue.
After installing the Microsoft Identity Web nuget package and setting up the app with razor pages, when I'm re-directed back to the app following an MS Sign out routine, i find that the logo image is no longer showing on the navbar.
This seems to be happening because the Microsoft Identity Web package is changing the URL of the page after signout i.e. its referencing a signout page that is now provided as part of the baked in package hidden away in one of the MD dll files.
My native javascript code is trying to load the logo image from my Images folder located on the root directory of my wwwroot folder structure, but because the signout page is changing the URL structure by adding a different path reference for the razor page, it's losing the path required for the image, not sure how to fix this?
js code that loads the image:
document.getElementById("navbarLogo").src = 'Images/CompanyLogos/Logo-LightTheme543by140px.png';
This image shows OK when I'm signed in normally or just browsing the site before sign in, so the issue only appears after being re-directed back to the site after an MS Sign out authentication flow.
The error shows 404, indicates that the image is not found, isn't blocked by identity. The image url may in layout, but the sign out page may not refrence the layout correctlly, or the relative path is not set corrcetlly. If it is not the problem, you can share this page code.
In the end I derived up the following solution which gave me what I needed:
// Because I'm using nested folders for the razor pages
// directory then I needed to re-construct the url path to
// to the images folder on wwwroot.
var urlPath = window.location;
var domain = window.location.hostname;
var port = window.location.port;
var baseUrl = 'https://' + domain + ':' + port;
Then using the above:
document.getElementById("navbarLogo").src = baseUrl + '/Images/CompanyLogos/Logo-LightTheme543by140px.png';
Poss not the cleanest solution but still works for me...

Google Site Verification Failure - HTML File Upload method

I have an Express/NodeJS app running on Google App Engine, for which I have the URL in the format of:
project-name.appspot.com, where project-name: My google project name
Now, for site verification, I am using HTML File Upload method.
I am serving the html verification file provided by google as follows:
res.sendFile(path.join(__dirname, path_to_html_file))
Now, when I enter the url: https://project-name.appspot.com/, I can view the file.
Also, the file has the same name as provided by Google.
However, when I click Verify in Webmaster, it still fails with error message "File not Found"
Can anyone point what I might be doing incorrectly ?
You need to serve this file from the /xxxxx.html url, not the root url.
In other words, it needs to be accessed from https://project-name.appspot.com/xxxxxxxx.html
Think about it... This file must stay up for as long as you want to be verified, so it doesn't make sense to be shown at the root url.
Also, make sure there are no redirects in serving this file.

In an XAgent inside XPages how to redirect to a new Window?

I have this XAgent with seems to work fine but it opens it in the CURRENT browser. How would I open it in a new window?
This code is running in After RenderedResponse of an XPage.
Thanks
// Track Downloads
// Setup XAgent stuff
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var fileLink = param.get("link");
// Insert Logging Code here
facesContext.getExternalContext().redirect(fileLink);
writer.endDocument()
Looks like you are trying to track when somebody clicks on the download link.
Without tracking the link would have been pointing directly at the file causing the browser to initiate the download and the user would stay on the current page. With the XAgent tracking in place the user is going to a different page in the application to do the tracking and initiate the download.
You could add a target of '_blank' to the initial link that is calling the XAgent. This will cause a new window/tab to open in the users browser but it will close once the download initiates.
Using this method of tracking the downloads will, however, remove the ability for the user of the site to be able to right click on your download link and do a 'save as'.
For a download link you could also consider to just stream the file using the OutputStream (there only can be one: Writer or Stream!) to directly serve the bytes of the file to download. You need to set the MIME type in the header. If it is not a file type the browser can handle, the download dialog will appear anyway. Opening a new window is actually considered bad style these days. If a user wants a new Window there is Ctrl+Click and Shift+Click -> a decision you shouldn't make for them (which opens the can of worms of browser illiterate users).

Resources