Angular JS file download - c#

I am trying to download file on a link click following this stackoverflow question Angularjs simple file download. After i click the link file downloads with error saying Failed No file. I have checked projects App_Data folder file is present there. Can anyone help figure out the issue.
<a target="_self" download="{{q.FileName}}" ng-href="{{q.QuizFile}}" href="#">Open File</a>
It renders into this path...
<a target="_self" download="Discussion.docx" ng-href="~/App_Data/74edf10b-5c18-472f-92bb-c64f55575b29/Discussion.docx" href="~/App_Data/74edf10b-5c18-472f-92bb-c64f55575b29/Discussion.docx">Open File</a>

The tilde in the path name doesn't mean anything in JavaScript. Its a convenience in mvc that resolves server side. Pass the path without the tilde.

Related

Why does my blazor page result in 404 errors on github pages?

I'm trying to set up a Github Pages site for my Blazor project. Even with a brand new blazor project I have had no success. I consistently hit 404 errors with an unmodified new project, following the instructions people have given on this question.
You can find my current attempt at https://billybillyjim.github.io and the repro is at https://github.com/billybillyjim/billybillyjim.github.io
My current process has been this:
Create a brand new Client-side Blazor page in Visual Studio 2019 Preview (3.0.100-preview6-012264).
Go to Github Pages and create a repo named billybillyjim.github.io
Clone the repo to a local folder using the Desktop Github app.
Using the Publish option in the Build menu of VS2019 I select a folder profile.
After a successful build I move the files created from the published folder to the repo folder.
I commit and push to github.
I add a .nojekyll file, and add the SPA javascript scripts to both a new 404.html and to the index.html.
Trying to load the page gives me a 404.
"Failed to load resource: the server responded with a status of 404 ()"
This error is for every dll file.
Things I have tried:
Putting everything in a folder, changing the base href in index.html, and setting the SPA script segmentCount to 1.
Removing underscores and updating the file references in index and the two blazor.js files.
Changing the href in index.html to to the repo name as described at the end of the instructions here.
I've compared my setup to the example page at https://github.com/blazor-demo/blazor-demo.github.io has a very similar setup to mine, but it's a year old and seems to use a very different set of dlls and a different blazor.js.
I am entirely new to web development, so I think it's very likely I am completely misunderstanding something simple.
The two key things that got it working for me were:
providing a base path in the blazor index page
removing leading underscores from folders (e.g. the _framework and _bin folders).
Fixing the base path
You need to do this because the files in the Blazor app are referenced to the root of the site, and a GitHub Pages site has the name of you project as the first part of the path.
In the index.html change:
<base href="/" />
to:
<base href="/YOURPROJECTNAME/" />
This makes the browser add in your project name to the start of the path of any files it fetches.
If you are storing your Blazor app nested in another subdirectory, you'll also need to include that in the base path.
You can tell if this isn't working by looking at the dev tools of your browser and examining the paths of any 404s it's hitting.
Fixing the leading underscores
I had to:
Remove the underscores from the folders
Rename the references to _framework and _bin in index.html and framework\blazor.webassembly.js
Automating it
I used some PowerShell post-publish of the app to combine both of these steps: (Note that you'll need to set the <base> tag to the correct value for your project)
(Get-Content .\public\blazor-sample\index.html) `
-replace '<base href="/" />', '<base href="/lifti/blazor-sample/" />' `
-replace '_framework', 'framework' |
Out-File .\public\blazor-sample\index.html
Rename-Item .\public\blazor-sample\_framework "framework"
Rename-Item .\public\blazor-sample\framework\_bin "bin"
(Get-Content .\public\blazor-sample\framework\blazor.webassembly.js) `
-replace '_framework', 'framework' `
-replace '_bin', 'bin' |
Out-File .\public\blazor-sample\framework\blazor.webassembly.js
I finally figured it out! I don't know how I didn't notice before, but my repo was not actually accepting my bin folder, which contains all the application's dlls. So it seems (Maybe by default?) Github pages ignores bin folders. First I tried to edit my repo's gitignore file, but it didn't seem to update to show files, so I had to manually add the files using git add -f framework/bin/ and then commit and push. Now the site is working!
For anyone finding this post and having issues trying to work with Blazor in Azure Static Web Apps, try creating a fallback route as this seems to fix the 404 errors you get when doing a refresh or by typing in a route manually.
In the root of your project folder (typically where App.razor and Program.cs are located), create a new JSON file named staticwebapp.config.json and put something like the following in it:
{
"navigationFallback": {
"rewrite": "/index.html",
"exclude": ["/images/*.{png,jpg,gif}", "/css/*"]
}
}
Assuming you are using GitHub, don't forget to push your changes, wait for the CI/CD action to finish, and then test. You should now be able to refresh a page and type in routes manually.
See Configure Azure Static Web Apps for details about the file and what else it can do. More specific detail about the example above (and a detailed explanation of why it's needed) can be found in the Fallback Routes section of the same page.
Worth noting, this method did NOT require modifying the base href or removing any _'s from bin or framework folders. I tested using the base "Blazor WebAssembly App" template in Visual Studio 2022.
Hosting a Blazor app on Git pages is a pain. I tried multiple ways and it results in error somehow. However, if you are looking for a free limited deployment option for a Blazor app then you can try Firebase.
You can refer to my article https://ankitsharmablogs.com/hosting-a-blazor-application-on-firebase/ for a step-by-step guide of hosting a Blazor app on Firebase.
What worked for me was:
1.Set your base href like this: <base href="home" />
2. Add a page directive to Index.razor so it looks like this:
#page "/"
#page "/home"
Use navigationManager.NavigateTo("home"); instead of navigationManager.NavigateTo("/");
You don't need to rewrite your base href in Github Pages.
Happy coding!
Indeed, anyone still looking for Answer in 2022
GitHub expects pages to be generated by Jekyll static site generator. So it will not read any folder starting with an underscore _.
You can now disable this behaviour by
adding a .nojekyll file to the wwwroot folder.
For GitHub Actions
If you are using GitHub Actions for deploying, add this step before copying the files
- name: Disable Jekyll
run: touch release/wwwroot/.nojekyll
Happy hosting. Don't forget to upvote if you find this helpful, so more people can benefit from the update :)

File or directory not found in IIS7 in asp.net?

I have published my project in IIS7. When I browse particular .ashx file in the browser, I got File or directory not found issue.
When I browse the same .ashx file in my local server file details have been shown. But in my local PC file details have not been shown. How to resolve that isse?
I would suggest you few steps:
Make sure you have added the file into your .Net project. The file is probably missing in your project.
Also double check the spelling. Sometimes is just a typo.
Type the path manually in your browser and see where it is looking for the file.
These options might be enough.

How do I add a Google Chrome plugin from my website to a browser

I have created a plugin. In that I have taken a folder and that folder contains an HTML page, manifest file, image and a .js file. Then I am loading the extension from load unpacked extensions from the Google Chrome extensions settings. Then the plugin is added to Chrome.
I have then packed the extension and I have gotten a .crx file and .pem file. I have dragged that file in to the Chrome folder and it is also adding it to Chrome.
I am including that file in a download link on my website like:
Download
And added the mime file type extension in the web.config file like:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".crx" mimeType="application/x-chrome-extension" />
</staticContent>
</system.webServer>
Now the file is downloading on link button click and it is getting an error:
Apps,extensions and user scripts cannot be added from this website.
My website is not live yet, I am using only localhost. How can I rectify this?
Any help is appreciated.
You can not trigger installation through <a href="#Url.Content("../test.crx")"
You should have a link tag <link rel="chrome-webstore-item"
href="https://chrome.google.com/webstore/detail/apdfllckaahabafndbhieahigkjlhalf">
You can trigger installation through chrome.webstore.install(url, successCallback, failureCallback)
For more information check documentation.

Img tag not showing image in windows azure cloud service

I deployed my MVC-3 project on the windowsAzure cloud service. Then when i opened it through
staging url. The images are not showns in my application. My image src is a relative address which is :
<img src="/images/1.jpg" alt="Lion" />
I am using jquery-UI as well but it plugins like ( button ) are also not working. I used cycle plugin, pagination plugin these are aslo not working. Whats the problem ?
altho your path 'appears' relative, you'll need to use the Url helper to navigate the folder structure correctly. Try using the below instead:
<img src='#Url.Content("~/images/1.jpg")' alt="Lion" />
All remote hosting is fickle and Azure is certainly no exception. This issue always catches me out if I omit the #Url.Content() helper. I'm certain this will work.
The problem probably is because your image is not imported in the MVC project. When you deploy a Cloud Service, only the resources that are in the project are deployed. Resources that are just in your file system are not.
I had this same issue and did the following:
my Images folder was outside the \Content directory, therefore, I created a directory inside this directory, so now I had \Content\images
I now moved my images to this new directory
Did a right-click on the images folder name in the Solution Explorer and clicked on option "Include in Project", I also did a right-click on the images itself and chose same option
Published and Voila it worked!
I had the same issue. I remote desktop to my server in Azure, opened IIS, went to the folder where I have the images and tried to Browse it, I got an Internal Server Error telling me "The requested page cannot be accessed because the related configuration data for the page is invalid". The issue was with this staticContent definition:
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
So I opened the web.config, searched for "mp4" and removed the section where I was defining that mimeMap.
After that I could browse the image and when I refreshed my page in my local machine all images showed up.
I then deleted that mimeMap definition from my Web.Release.config file. I had created it because previously I had published this project as a WebSite in azure and I couldn't deliver mp4 videos using the tag, but that seems not to be necessary when using a Cloud Service.
Hope this helps.

ASP.NET Master Page Parse Error

I have a Visual Studio 2010 project with a Master Page that works fine.
~/Site.Master
In the same project is a Folder with another directory structure that needs to use another Master Page.
/xr
Within this folder, I have included the Master Page for those files.
/xr/XR.Master
My Default.aspx file attempts to access this Master Page using the following include:
<%# Page Title="XR Project" Language="C#" MasterPageFile="~/xr/XR.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test1.Default" %>
Debugging on my machine in localhost works fine, but whenever I deploy it and try to navigate to the Default page in the xr folder, I get
Parser Error Message: The file '/xr/xr/XR.Master' does not exist.
However, the Source Error returns Line 1 as I have shown above.
Here is what I tried:
I moved the XR.Master page into the root folder and changed all of the files in the xr folder to reference the XR Master Page using the following include:
I debugged and tested the code on my machine using localhost, and it worked fine.
I pushed it out to the remote website and got the new error:
Parser Error Message: The file '/xr/~/XR.Master' does not exist.
What am I doing wrong?
EDIT: I do not like posting a link to the page, but I will for a short time until this is resolved:
Projects
From there, you will see everything works well enough except for the link to XR1200.
Here's the best advice I can give ya without knowing too much about your project structure.
I'm hoping you are using VS2010 so that things will look the same for you as on my machine.
One easy way to get the path of your master page all figured out is to add a test web page from masterfile, the path will be preset for you and you can use that in your existing pages.
Here is my blogs project structure.
Right click the folder where you want to add the test page and click add new file.
Add a new web form using Master Page. This is just for testing.
Now locate your Masterpage and select it.
From here just find your newly added content page in your solution structure and check the code files for the path to your masterpage.
Once you've verified that your path is correct, if it still bombs once you publish it then you've got either an issue where not all of your projects are building properly, or you're files aren't being uploaded properly and that is going to end up being something that you may just have to find on your own. I still suggest blowing away anything in your pub folder on your server and trying a clean publish.
Hope this helps!
my guess is that the iis setup is different on the different machines. typically, you see something like this when you have one machine set up with the site itself as a website and another machine set up with the site itself as an application within a website (like the Default Website). it looks like you have addressed this possibility by using the ~ in the path, but perhaps the iis on which you are deploying does not have the site directory itself set up as either a website or an application, but is merely a subdirectory of a site. in that case, the ~ would refer to the website directory (perhaps named xr?) and the site is in a subdirectory of that named xr. if this is the case, the solution is probably to set up iis such that you have the application directory configured as an application on the server to which you are deploying.

Categories