All Invalid Random Paths in the URL Return The Normal Web Page Instead of 404 Not Found Page - url

I have a website:
https://www.includekarabuk.com
For instance this url contains an article:
https://www.includekarabuk.com/kategoriler/genel/Siber-Guvenlikte-Dusuk-Seviye-Aciklik-Nedir.php
But when I add invalid path to the existing url, page is still being showed.
https://www.includekarabuk.com/kategoriler/genel/Siber-Guvenlikte-Dusuk-Seviye-Aciklik-Nedir.php/test123343242314321423423423/
https://www.includekarabuk.com/kategoriler/genel/Siber-Guvenlikte-Dusuk-Seviye-Aciklik-Nedir.php/sdfdsfdsfsdfdsfsdfsdfsdfsdsdfdsfsdfd/
https://www.includekarabuk.com/kategoriler/genel/Siber-Guvenlikte-Dusuk-Seviye-Aciklik-Nedir.php/132432432/
But because css and javascript file locations will be invalid due to added extra path, page is displayed as broken.
I want to stop this. When the web server receives invalid path as with above, it should respond as 404 not found page coming from web server. How can I do that? I am using Apache web server and php scripting language.
Note: I am not using any MVC framework.

Related

Access to a PDF File in a http with dinamyc variables

Hello everyone (sorry for bad English), i'm getting crazy with this problem... i'm working on a project with NiFi expecting to download PDF files from a public Goverment page. The main problem it's that the page you request in a web browser shows the correct page like this
Asking the same page in NiFi (also testing in postman) shows that the session has expire, then looking at the HTTPS POST with the development tools in chrome i notice that there are multiple headers that contain dynamic variables
Is there any form to replicate web browser behaviour on NiFi?

IIS url rewrite ignores .chtml ( Razor ) files

I have a rewrite rule that says.
site.one/content/templates/whatever.cshtml -> site.two/content/templates/whatever.cshtml
The problem occurs when site.one trying to fetch .cshtml files. It returns a 404.
However if i change the extension to .js or .html then the rule works.
If i use the site.two link the request handles it just fine, this is without any rewriterules ofcourse.
site.one can also handle .cshtml files from within its own directory.
Iam using IIS 10, Urlrewrite module 2, and Application Request Routing 3.
UPDATE
So the .cshtml in this case are template files that is fetched with async text.js, and then gets compiled with handlebars as the last step before rendered, but some of them need to get processed by razor engine because of the translations. This works if not rewriting.
Razor files are never served by the MVC framework or IIS. Razor files are processed by MVC and the result of the processing is sent to the output through a controller action method. The server is correctly responding with a 404 response in this case, because these files are blocked by default (you would never want to serve an unprocessed .cshtml file with source code to the user).
Since these files are blocked by IIS, there is no way to redirect them using the URL Rewrite Module (nor should there be).
I am guessing that you probably want to redirect your MVC URLs, which don't have an extension by default. The default way they are accessed (which can be customized) is /{controller}/{action}/. For example, the in the MVC template the default way to get to the about page is through the URL /Home/About/.

MVC .Net Redirect to remote unhosted html file

I am trying to redirect to an unhosted html file in an MVC action. The page returns with corrupted content error. I am trying to redirect like this:
return Redirect("file:///C:/test/mytestfile.html");
This of course works fine if the file is on a web server:
return Redirect("http://myserver/mytestfile.html");
Is it even possible to use the file protocol when redirecting in MVC? I've also tried:
return new RedirectResult("file:///C:/test/mytestfile.html");
and
Response.Redirect("file:///C:/test/mytestfile.html");
The project I'm doing this in is a bridge solution to overcome some shortcomings in a vendor solution, so unfortunately I can't just move the target files to web server. I really need to redirect to the file on the share where it lives.
This is not supported and is not a limitation of ASP.NET MVC, it is how web browsers work. You cannot redirect to the file:/// protocol if the web application is hosted on a web server (http://). You can only redirect to file:/// if the page that is redirecting is also hosted on file:///.
More info on the subject can be found here and the rules are defined here.
You could possibly have the website do a file read on the HTML file and then output the file to the page. This might be a start. You would end up with a wrapper "page" on your site that mirrored the remote HTML file.

ASP.net mvc How to handle 404 which caused by missing of file

I have file in folder "/UploadDir/TextFile1.txt"
I need:
download file if it exists
if file not exists (for example url :"/UploadDir/TextFile2.txt") should be shown custom errors message.
But now my mvc application not handle any requests to missed or existing files, when i place breackpoint on Application_BeginRequest and try to request text file - nothing occurred.
Besides i tryed to override HttpNotFound and HandleUnknownAction but same unsuccessfully.
Who can help me how to hande request to file if it exists or show custom error if it not found.
ps. route configuration is default
It sounds like the request GET /UploadDir/TextFile1.txt is being handled by IIS and not being passed into the ASP.NET pipeline. IIS will attempt to serve the content using its static file handler due to the .txt extension, and discover the file does not exist, issuing a 404.
You need to change your configuration to make these requests be passed to the ASP.NET handler for further processing. The exact details of that depend on your version of IIS.

asp.net mvc routing, ignore route with extension in the middle of url

Hi How can make the asp.net routing engine ignore routes with an extension of the type
/pathtofile/filename.aspx/morepaths
I know this is hardly a real scenario but I need to know for another similar issue for an autogenerated url
Thanks
The MVC routing engine will not intercept a url if there is a matching file on the file system. (See RouteCollection.Ignore Method) So your example url will work fine. Query strings will also work fine.
You can test this out as follows:
Create an MVC application in Visual Studio
Run it
In your browser enter the url of the Site.css file in the Contents folder.
The file will be served and the browser will pop up the "Save" dialog.
Create an html file anywhere on the site and enter the url.
Your browser will display the html page.
Create an aspx web form anywhere on the site and enter the url.
Your browser will display the web form.
Add a query string or additional path to the url.
Your browser will display the web form.
You can also do this with .asp (classic ASP) pages (although the VS web server won't serve .asp pages, you have to set the site up in IIS for that to work.)
I hope that answers your question.

Resources