Remove link to document caching in ASP.NET - asp.net

I'm trying to append DateTime.Now.Ticks to my link to stop it from caching as I'll be replacing it often. The problem I'm having when I do the code below is that it's adding a Content path in the url.
The original link was:
<a target="_blank" href="~/Documents/Data/Acct/MyDocument.pdf">Document</a>
This obviously caches the file on the browser so when I overwrite MyDocument.pdf the users don't see that unless they Ctrl-F5. So I changed it to the following:
<a target="_blank" href=#string.Format("{0}?t={1}", "~/Documents/Data/Acct/MyDocument.pdf", DateTime.Now.Ticks)>Document</a>
This produces a link that looks like: Content/~Documents/Data/Acct/MyDocument.pdf" which obviously doesn't exist because it's adding in Content and keeps the ~. If I remove the ~ I still get Content/Documents/Data/Acct/myDocument.pdf. How do I stop .NET from adding this Content/ to my link?
To add, the page that this link is in, is inside a folder called Views/Content. So I guess that's where it's being called from, but the ~ I assume should go up a level but it's not.

<a target="_blank" href=#string.Format("{0}?t={1}", "../Documents/Data/Acct/MyDocument.pdf", DateTime.Now.Ticks)>Document</a>
If you want to go up a level in your Url use ../ should get rid of the Content

Related

how to get the dynamic loaded content from a webpage (Alphafold database)

I think similar topics may have been discussed before. But I still could not find the solution. Here is the example page
https://alphafold.ebi.ac.uk/entry/P82662
I want to extract the target downloading URL:
https://alphafold.ebi.ac.uk/files/AF-P82662-F1-model_v4.pdb
When I "Inspect" this page in Chrome, I could see the desired URL here:
<a _ngcontent-brn-c12="" class="vf-button vf-button--secondary vf-button--sm" style="color: #3B6FB6;" href="https://alphafold.ebi.ac.uk/files/AF-P82662-F1-model_v4.pdb">PDB file </a>
I used request.get to get the html but could not find the target URL, and realized this could be dynamically loaded. Then, under the Network tab and Fetch/XHR I could only see a similar URL without the desired file type:
https://alphafold.ebi.ac.uk/files/AF-P82662-F1-model_v4.cif
So how can I get this URL string using request?

Download links in Blazor

I'm programatically creating links to download files of different formats like .csv and .yml.
My code is
<a href="/organs/#organ/#policy/#folder.Name/#file.Name" download>#file.Name</a>
so lets say these links get created:
https://localhost:44372/organs/Heart-Lung/03-15-2020/data/fakedata.yml
https://localhost:44372/organs/Heart-Lung/03-15-2020/data/testdata.csv
the .csv works as it should, I click and it downloads. the .yml however opens a new web page at that link and then says that it can't be found
I'm really not sure what I'm doing wrong, is there a way force it to download or should I be doing this a different way?
I ended up using javascript to do this, based on https://wellsb.com/csharp/aspnet/blazor-jsinterop-save-file/
most of the code is the same, but I changed the link to this to pass in the variable and to keep it as a clickable link that doesn't go anywhere
<a href="javascript:void(0)" #onclick=#(() => DownloadFile(file.FullName))>#file.Name</a>

Download attribute in <a> tag doesn't work when file URL called from sub domain

I have a blog here where I have used an anchor tag (<a>) with the download attribute for an HTML file:
</i>
Screenshot:
Expected: when the user clicks, it should open the dialogue box to download the file.
However, it navigates to the file. AFAIK, it was working earlier. Not sure what happened, or am I missing something? As per this w3schools example, ".html" file is allowed.
Any help would be much appreciated without using JavaScript.
EDIT:
This blog is in a subdomain (http://blog.idevelopweb.site/) and I'm calling the HTML file which is in the root directory (http://www.idevelopweb.site/) so I have used an absolute path.
I may direct you to here.
Your problem is the same origin policy of the download attribute. So either use the same url or relative path.
Download file when clicking on the link (instead of navigating to the file):
<a href="link" download="logo">
Note: The download attribute is not supported in Edge version 12, IE, Safari 10 (and earlier), or Opera version 12 (and earlier)
In your Code
</i>
The href contain link of the webpage instead of the data , image or file which nedded to be downloaded. The webpage cant be downloaded using download attribute of anchor tag.Thus it should be in format:
<a href= "--link of image or file to be downloaded--" download > Download </a>
For example:
<a href="/images/myw3schoolsimage.jpg" download> Download </a>
This download the myw3schoolsimage.jpg image

Razor Page - How to redirect to another folder's page using asp-for tag helper

I've been having issues with this but I think is simple.
asp.net core 2.0 Razor Pages
I have a Users/index page and I added a link to take me to the child records under Entries Folder.
Structure is like
Pages
/Users
/Entries
Under /Pages/Users/index.cshtml
<a asp-page="./Edit" asp-route-id="#item.Id">Edit</a> |
<a asp-page="./Details" asp-route-id="#item.Id">Details</a>|
<a asp-page="~/Pages/Entries/" asp-route-id="#item.Id">Enter Child Records</a>
However, on the browser, looks like is not rendering the correct link. It staying under the default page.
I tried asp-page="../Entries/" and other combinations with no luck.
Can't believe this but this works.
<a asp-page="../Entries/Index" asp-route-id="#item.Id">test</a>
I think your own answer might add confusions to others. First of all, you're talking about LINKs to another page, not redirect to another page. Razor Pages have a designated function for page redirections.
About the asp-page tag helper, it's interpreted by the code-behind engine (e.g. C# syntax) and so the "~" doesn't work. Basically, asp-page is expecting a name. In your own examples:
<a asp-page="./Edit" asp-route-id="#item.Id">Edit</a> |
<a asp-page="./Details" asp-route-id="#item.Id">Details</a>|
will work, but they should be shortened as:
<a asp-page="Edit" ...>Edit</a> |
<a asp-page="Details" ...>Details</a>|
because they are in the same folder as your /Users/Index page. As you know the "./" part just means going up one level to your parent folder and so it's redundant. You don't want to instruct your engine to go up one level and then come down again to the same folder immediately.
When you need to switch to another containing folder, going up two levels and specify the new folder name. So, the "../NewFolder" works.
If it is at the web site root level, you can use the root syntax directly for faster routing. So both of these work the same if AnotherFolder is under root:
<a asp-page="../AnotherFolder/Index" ...>test</a>
<a asp-page="/AnotherFolder/Index" ...>test</a>
The asp-page tag helper is expecting a real page name at the last part and hence the quoted text must be ended with a page name. You cannot use asp-page="/Entries/" as in HTML URLs and expect the engine to default to Index page for you.
Lastly, to cover redirecting pages, code-behind has a function called return RedirectToPage(string pageName, ...), and its first parameter uses the same page routing syntax as the asp-page tag helper described above.
There is also a Redirect() function that works with pages outside your Razor Pages system, which can take any URLs as your browser or HTML code do. That's another story.

Disable a single link with rewrite_hash_links in silverstripe

I have a link in my page.ss that needs rewrite_hash_links set to false.
<span class="glyphicon glyphicon-menu-hamburger"></span>
I've found the documentation but have no idea how to apply it to just the one link. https://docs.silverstripe.org/en/3.1/developer_guides/templates/how_tos/disable_anchor_links/
So, do you want the #menu link to go to <root of site>/#menu?
This is what simply disabling the rewrite would do, assuming you still include the base tag in your source.
In any case the rewrite_hash_links functionality only applies to unqualified hash links. In other words if you put an absolute URL in the link, it shouldn't be rewritten.
Example
...
or:
...

Resources