Failed to load resources - c#

I have application which I deploy to Azure and suddenly I catch one error which wasnt in my local machine when I tested application.
Failed to load resource: the server responded with a status of 404 (Not Found)
SO when I tested application in my local machine everything works perfect without any errors, and when I move to test application live on server many option doesnt work, and in console manager I get this kind of error.
Any help, what can be problem here ?

404 is resource not found error. Most probable reasons are your files are in “../“ folder and you are trying to access file in “../..” folder.
I would suggest using URLs like /Folder/subfolder instead of relative URLs like “../parentfolder/subfolder”..
Also, its good to use “~”..
More on paths here:
https://msdn.microsoft.com/en-us/library/ms178116.aspx

Related

Unable to determine if a file is on a web server because the various methods of determining the directory do not work

I am developing an application in asp.net, vs2015 using c# and the development environment is a Win10Pro machine. I can use any of the various methods to obtain the working directory and see if a particular file exists on the dev pc, but not on the Web Server. I have tried the methods laid out on:
Get current application physical path within Application_Start
All work on the Dev PC, but when used on the Web Server it will not return the working directory. The Server is a 2016 Data server using IIS10. The issue is that the web site I am putting together work fine, except to display GrapeCity ActiveReports reports AR15. The web page containing their web viewer opens just fine and is looking for a report file (MyReport.rdlx). The global.aspx file is pointing to the root directory but when the web viewer opens up, it says File Not Found. I have absolutely no idea and tech support is not sure. Is this an IIS issue that is preventing the code to locate and verify the file is there? Any direction would be much appreciated. This has been very frustrating and time consuming.
AppDomain.CurrentDomain.BaseDirectory does not work, HttpRuntime.AppDomainAppPath does not as well as all the others. The request comes back blank.
string filename = AppDomain.CurrentDomain.BaseDirectory.ToString() +"SPU01_Dates.rdlx";
if (File.Exists(filename))
{
Response.Write("YES");
}
else
{
Response.Write("NO");
Response.Write("</br");
Response.Write(filename);
}
All this just returns nothing.
Thanks.
Try this code
if (File.Exists(Server.MapPath(filename)))
Check if a file exists on the server
In my test, it returned YES and worked well. Did you put "SPU01_Dates.rdlx" file in root folder?
In the development environment, it returned YES, and when I deployed it to IIS, it returned NO. I found that during the deployment process, the rdlx file was not deployed with the project, so I recreated one in the deployed folder, and it returned YES.
The test proves that AppDomain.CurrentDomain.BaseDirectory is the most accurate way to get the file path. When you test this code in IIS, does it return NO or empty? Returning empty means that this piece of code has not been executed.

Server.Mappath() fail on remote server

i use like this codes for prepare paths.
string path = Server.MapPath("~/"+ User.Identity.Name+ "/file.zip");
i take this error when i run this code on localhost
Index:582 Not allowed to load local resource: file:///C:/Users/trkmml/Documents/GitHub/OfisTakip/trkmml/file.zip
i think its not problem (its chrome security thing). anyway file path is correct.
On the other hand, when I upload the program to hosting, it adds "file:///C:/Inetpub/vhosts" to the front of the link. how can i cancel this part. how do I make it just
http://example.com/httpdocs/trkmml/file.zip".
here is error on remote host
Not allowed to load local resource: file:///C:/Inetpub/vhosts/example.com/httpdocs/trkmml/file.zip

I am getting error while moving file to NAS path

I have a web application to upload file. Application first store file to local server and then move to NAS path. Application is using System.IO.File.Move method of C# to move file from local server to NAS.
I am seeing strange issue. After login to application first upload works fine. but if upload another file immediately,it fails. If I wait for 3-5 minutes after a file upload and try to upload file again. it works.
I have tested the connectivity from local server to NAS, it is fine.
Same web application was running on another server, we have stopped application on that server and moved to this server. This issue is happening only on new server not on old server.
Error message:The specified network name is no longer available.
Line of code which throw error: File.Move(sourceFilePath,DestinationFilePath)
Also I was trying to see if connection to NAS path has issue. So what I did is that just before the line of code which is throwing error I added a condition:
If(!File.Exist(DestinationFilePath)){ throw new Exception(<some message>)
After adding this check application is working fine. I am not sure how?

Failed to load resource, error 404, running with IIS Local

Good morning, I developed a mvc 5 application, during development I used IIS Express, all the files there loaded perfectly, when I uploaded to my IIS Local (7) still on my machine to test, I realized that several files are not loaded.
Failed to load resource: the server responded with a status of 404 (Not Found)
glyphicons-halflings-regular.woff
When checking I identified that the file is not loaded because in fact, the path that tries to perform the GET is incorrect. It tries to get get on the path:
http://localhost/content/fonts/glyphicons-halflings-regular.woff
But the correct file would be:
http://localhost/aprovacoes/content/fonts/glyphicons-halflings-regular.woff
In the get, the project name is missing, due to this it is not loaded.
To solve the problem of this particular source, I needed to edit the bootstrap.min.css file and change the url from url:
url(/content/fonts/glyphicons-halflings-regular.woff)
for
url(aprovacoes/content/fonts/glyphicons-halflings-regular.woff)
However in every project several files are not loaded, and to solve I'm editing the css file by file, would not there be another way to map this correct path in all css files?
Thank you very much in advance
Use a resource-relative path. For example, if you have a file structure like:
+ bootstrap.css
- fonts
+ glyphicons-halflings-regular.woff
Then, use the URL: fonts/glyphicons-halflings-regular.woff. Or if it's something like:
- css
+ bootstrap.css
- fonts
+ glyphicons-halflings-regular.woff
Then, you'd use: ../fonts/glyphicons-halflings-regular.woff.
That way, it won't matter how or where the site is deployed, as long as the relative path between the files remains consistent.

Printing Telerik reports using ReportProcessor class

Firstly let me describe my setup.
I have a REST Telerik Reporting service. The service operates with TRDX file (have a requirement to have reports in this template format). I also have a console application, which is periodically started by a windows service. This console application uses ReportProcessor class to print reports directly to a printer.
Now the problem.
ReportProcessor throws an exception when trying to access the reports using UriReportSource, when these report files are hosted in IIS together with the REST Reporting service. Browsing and Anonymous Authentication are enabled on IIS for the Reports folder. The error that's thrown is:
The remote server returned an error: (404) not found.
However reports are printed when TRDX files are located in the same folder as the console application.
Solved my own question by trial and error.
My reports were located in the REST service's subdirectory. So I was trying to set the Uri to the reports URL something like this:
UriReportSource reportSource = new UriReportSource {
Uri = "http://localhost/myTelerikRESTService/Reports/samplereport.trdx"
};
And I was obviously getting 404 error since the request to the that path would be handled by the service.
Trying to specify a physical path (c:\inetpub\wwwroot\myTelerikService\Reports\samplereport.trdx) also ended up in error: something like the path format is not supported.
Finally I've tried this Uri: /inetpub/wwwroot/myTelerikService/Reports/samplereport.trdx, that maps to the physical location.
And it worked!
EDIT:
I really should've read this https://www.w3.org/Addressing/URL/uri-spec.html before working on this issue. Apparently I had no firm understanding of what a URI is! Feeling really dumb now.....

Categories