Conditions:
The files must be opened outside of the window that the link to them is in.
I have tried href, but when I give it an intranet link it only opens correctly if I leave out target="_blank"; if I put that in, the new window that opens doesn't receive the full link if there is a pound sign in the filepath... a direct link to the intranet address \a\b\c#c.txt would be fine with me; there is no concern about security, but I can't seem to get that to happen in a new window. It seems like this is happening when I don't create a new window, but I can't utilize the same window to open the links.
Any ideas?
It's a bit of a hack but try changing the links to href="#" onclick="window.open('http://' + escape(restofurl))"
Even if you can get the link to work, the user accessing it may or may not have rights to see that machine.
What I do in cases where I have to link to other files on other server, is link to a generic handler(.ashx file) that does impersonation of user that does have rights, or impersonates the logged-in user. The handler then reads the contents of the file and streams it to the user.
Have you tried streaming the file contents to the browser?
Related
My project is an Asp.Net MVC4 web application.
Currently it has a method to generate a text file and send it to the client's browser for download.
I need to modify it to force the browser to save the file in a custom (pre-defined) location on the client's computer.
This will not be possible as it would introduce a severe security problem. A user has to decide where the file will be saved.
You can only specify a location on a server to which you have access to.
If its an internal site, then you could setup the server to save the file to a network location and return that path to the user..
If you want to show a save as, add this to your ActionResult to indicate a file download:
Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });
return myFileStreamResult
I needed to download and sort files into a rigidly defined directory structure on the client machine with no possibility of user mistakes. Ideally it would be completely automatic. I couldn't make it fully automatic, but in Chrome in Windows, I eliminated the possibility of typing mistakes with:
<a class="aDownload" href="file.txt" download="CTRL+V for suggested path/file">Download</a>
<textarea id="textareaClipboard"></textarea>
Using jQuery to listen for a click of the link, I call a function to generate the desired path and final file name, put it in the textarea, and transfer this to the clipboard using
jQuery('#textareaClipboard').select();
document.execCommand('copy' ,null ,null);
The Save As dialog pops up with "CTRL+V for suggested path/file" in the file name field. Follow the suggestion to paste the generated file name into this field, and hit Enter.
It requires a minimal amount of user action to ensure the file goes to the right directory with the right name, and the user can always reject the suggestion.
Your web application only can sending file to your client. its imposible to force download and save to spesific location, because download and save to privilege is belongs to client browser.
if user not defined default download location, it will prompt save to when download something, then if user already defined default download location. it will download automatically and save to default location.
so i think you have a little misconception with your web logic :D
I need to provide a way for corporate users to view/download an excel file that's located on a network share. I'm sure that IIS has read access to that location, and I can navigate to it via the browser like so:
\corp.it.com\root\shared\test.xls
But for the life of me I can't get this to work with an href or a hyperlink or a response.redirect. I've tried a bunch of different things - slashes in both directions, prefacing it with file://, but no luck. I've also tried impersonating a valid user and I can read/copy the file from my code, but I can't use that impersonation to actually navigate to that location.
Any thoughts?
Thanks.
This shouldn't involve IIS at all, you just need a correctly formatted file://... URL. As the spec is file://machinepathisvalidfrom/path, you can omit the machinepathisvalidfrom as localhost is implied but you MUST leave the \s in place. This leaves file:\\\ followed by the UNC with / changed to \:
file://///server/share/file.txt
Note that this can be browser dependant.
See the file:// spec, and other sources
I am developing a internal app in c# which calls one of the banking site. I need to enter curency in DDL, amount in textbox and neeed to find out the exchange rate.
here is the link which i need to use..
https://www.timesofmoney.com/remittance/secure/rmtExchRateCalculator.jsp?tab=US&sendercountry=US&sendercurrency=USD&uiId=TOML&partnerId=TOML
I used myWebClient.UploadValues(C#) but the site is returning some errors...can some one help me with this..
My Code:
string uriString= "https://www.timesofmoney.com/remittance/secure/rmtExchRateCalculator.jsp?tab=US&sendercountry=US&sendercurrency=USD&uiId=TOML&partnerId=TOML";
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();
// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("selCountry", "United States");
myNameValueCollection.Add("rmtAmount", "100");
byte[] responseArray = myWebClient.UploadValues(uriString, myNameValueCollection);
Response.Write(Encoding.ASCII.GetString(responseArray));
The response I got from the site:
Inconvenience Regretted !
Please check your browser settings to enable you to use the site. You may be facing this problem due to old cookies and temporary internet files
Delete the temporary Internet files.
To delete the temporary Internet files, follow these steps:
Start Internet Explorer.
On the Tools menu, click Internet Options, and then click the General tab.
Under Temporary Internet files, click Delete Cookies.
Click OK when you are prompted to confirm the deletion.
Click Delete Files.
Click OK when you are prompted to confirm the deletion.
Under History, click Clear History.
Click Yes when you are prompted to delete your history of visited Web sites.
Click OK.
Close all open browsers and restart new browser again
It seems like the page requires cookies. Take a look here to see how to handle cookies with WebClient.
To debug your problem you can also install a header sniffing tool like Live HTTP Headers for Firefox or ieHTTPHeaders for Internet Explorer and try to send the same information via WebClient (same User Agent, Referrer etc.).
You can try www.coinmill.com. I used javascript to get the exchange rate/currency conversions of there site with no problems. Hope this helps
I have a web page (asp.net) that compiles a package then redirects the user to the download file via javascript (window.location = ....). This is accompanied by a hard link on the page in case the redirect doesn't work - emulating the download process on many popular sites. When the IE information bar appears at the top due to restricted security settings, and a user clicks on it to download the file, it redirects the user to the page, not the download file, which refreshes the page and removes the hard link.
What is the information bar doing here? Shouldn't it send the user to the location of the redirect? Am I setting something wrong in the headers of the download response, or doing something else wrong to send the file in the first place?
C# Code:
m_context.Response.Buffer = false;
m_context.Response.ContentType = "application/zip";
m_context.Response.AddHeader("Content-Length", fs.Length.ToString());
m_context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}_{1}.zip", downloadPrefix, DateTime.Now.ToString("yyyy-MM-dd_HH-mm")));
//send the file
When a user agrees to download a file using the IE Information Bar, IE reloads the current page, not the page the file the user is trying to download. The difference is that, once the page is reloaded, IE will allow the download script to go through without prompting the user. I'm not sure what the thinking is on this from a design standpoint, but that's how it seems work.
I have a situation in which there is a login page.After successfully logging in,i 'm redirected to http:\localhost\default.aspx.I want that after logging in my browser url should look like www.abc.com but the pa ge opened would be http:\localhost\default.aspx.I'm not able to do this using URL rewriting
Unfortunately, this is not possible for internet users - you can't 'fake' the URL that your user is looking at. Otherwise evil-doers could re-write 'www.istealyourmoney.com' as 'www.trustworthybank.com', etc.
The only possible option I can think of is if your users are all on the same local area network. In that case, you can add an entry to your HOSTS file with www.abc.com aliased to 'localhost'.
As said by JBRWilkinson this is not generally possible, however if you want to do this just to help you build out a site while you work on it locally, add an entry to your HOSTS file (on Windows: C:\Windows\System32\Drivers\Etc\Hosts) that maps www.abc.com to 127.0.0.1. You want to add a line that looks like this to the end of the file:
127.0.0.1 www.abc.com
Then you can access your local development website with the URL www.abc.com. Note that this will also block access to the live version of that website on your machine.
can't we achieve using IIS url rewrite?
http://www.codinghorror.com/blog/archives/000797.html