I have created a web application using Microsoft Azure and uploaded static html pages to the web application.
It works fine, however, I would like to set a custom 404 page. Where or how can I do this using the Azure portal ?
Just to be clear, this is not a visual studio project, it's just some static html files. I just want to tell azure to use my 404 page instead of the default text it displays when a page cannot be found.
EDIT
Please note, this has nothing to do with IIS. I dont even have a web.config file. I am simply hosting some static html files in Azure and want a custom 404 page. I have already made the 404.html page.
Seems like you have to add a web.config file in your root directory. This seems like a workaround, but doing that and adding the following code works:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
Follow these steps to configure a custom 404 page for a Azure Static Web App:
Create a file named staticwebapp.config.json in root page (same folder as starting page i.e. index.html)
put these lines inside it:
{
"responseOverrides": {
"404": {
"rewrite": "/404.html"
}
}
}
Put your custom 404 page in root or subfolder (in this example 404.html is in root folder)
After a lot of testing and research, it was found that using responseMode="ExecuteURL" would result in a correct redirect, but the browser would report 200 Status rather than a 404. To fix this we removed the "/" and changed to responseMode="File" based on insight from this post: web.config errors fail with responseMode="File"
We are just hosting a simple static HTML site, not a web app, and this code worked:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors defaultRedirect="404.html" mode="RemoteOnly">
<error statusCode="404" redirect="404.html" />
<error statusCode="500" redirect="500.html" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors existingResponse="Replace" defaultResponseMode="File" errorMode="Custom">
<remove statusCode="404" />
<error statusCode="404" path="404.html" responseMode="File" />
<remove statusCode="500" />
<error statusCode="500" path="500.html" responseMode="File" />
</httpErrors>
</system.webServer>
</configuration>
Related
I try to redirect users that have no autorization for different pages from my app to a custom error page: CustomErr/Forbidden_403 - controller(that have a razorview). I've also configured <customErrors> in my Web.config but I need <httpErrors> too because for some reason, when I publish to the server, this 403 error is not overriden(more it shows 404 not found error instead of 403).
I need a relative path to the View: path="~/CustomErr/Forbidden_403" because my server have multiple apps and each app have it's own folder.
What I've seen so far:
If I add subStatusCode with or without relative path("~") : <error statusCode="403" subStatusCode="14" path="~/CustomErr/Forbidden_403" responseMode="ExecuteURL" /> then the browser return a HTTP 403 error page ("The website declined to show this webpage")
If I remove subStatusCode: <error statusCode="403" path="~/CustomErr/Forbidden_403" responseMode="ExecuteURL" /> then the browser shows a HTTP 404 error("The webpage cannot be found")
If I remove subStatusCode and relative path("~"): <error statusCode="403" path="/CustomErr/Forbidden_403" responseMode="ExecuteURL" />then the browser return a HTTP 403 error page ("The website declined to show this webpage")
I also have a PageNotFound_404 Controller and error defined in web.config which is working fine if I write down an incorrect URL in browser.
The custom error is not showing only for 403 Forbidden => I user return new HttpStatusCodeCresult(HttpStatusCOde.Forbidden) for throwing this 403 code to server.
Web.config
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="403" />
<remove statusCode="404" />
<error statusCode="403" path="~/CustomErr/Forbidden_403" responseMode="ExecuteURL" />
<error statusCode="404" path="~/CustomErr/NotFound_404" responseMode="ExecuteURL" />
</httpErrors>
Do I need to configure it from IIS?
What I eventually did was to override paths from Web.config in Web.Release.config
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="403" />
<remove statusCode="404" />
<error statusCode="403" path="/myAppFolder/CustomErr/Forbidden_403" responseMode="ExecuteURL" />
<error statusCode="404" path="/myAppFolder/CustomErr/NotFound_404" responseMode="ExecuteURL" />
</httpErrors>
Also all js files with ajax that have url to controllers, I've modified urls from url:"/Controller/Action" to url:"Controller/Action" - they will automatically figure relative path.
You should remove subStatusCode and relative path("~"), and shouldn't the end of the value of your path be html or htm? below code works on my side.
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="/Errors/404.html" responseMode="ExecuteURL"/>
</httpErrors>
I am trying to block (using web.config) direct access to mp4 videos while allowing videos to be played within the website:
Here's my current web.config's content. This blocks videos to be played on my HTML page as well as direct access.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".mp4" allowed="false" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
How can I allow video to be played on HTML while blocking direct access?
You can put your “Uploads” folder outside the website directory, so if your website exists on “c:\website” you can put the “Uploads” there “c:\Uploads”, Like that IIS has no control over this folder and its files, And your website code will still have access to this directory as a normal physical path.
or you could try to set the hidden segment in web.config file:
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="Uploads" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
I'm having a problem with a deployed webapp service in AZURE, the videos contained in the web page are not working.
The message is the next one:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
The HTML code is the next one:
<i class="icon-play2"></i>
Can anyone help me please?
Thanks!
As #Offbeatmammal mentioned, we need to configure the MIME types in web config file before we use the specific file type in our web application. Since your video type is mp4, you need to add following configuration into < system.webServer > tag.
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
</staticContent>
Yes thank you! Solved with a web.config file!
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
<mimeMap fileExtension=".ogv" mimeType="video/ogg"/>
<mimeMap fileExtension=".webm" mimeType="video/webm"/>
</staticContent>
</system.webServer>
So I have a .NET MVC app published in an Azure Website which should serve static html pages stored in a blob container when clicking on a corresponding hyperlink.
My questions are:
The way to access a blob in Azure is
https://blobtest.blob.core.windows.net/container/htmlpage1.html,
however the peculiar part is when I login into my Azure Site and the url is
something like:
http://azuretestwebapp.azurewebsites.net/user123 and if I click
on a hyperlink to my html blob it can't help but normally take me to
blob azure site (well of course). Therefore I am wondering if there
is a way to have a url similar to this:
http://azuretestwebapp.azurewebsites.net/user123/container/htmlpage1.html
considering that the html pages are stored elsewhere in Azure.
If this is not feasible using an Azure Website or by storing
static html pages in Blob, what would be a better approach?
Thank you in advance for your time.
You can modify your web.config for your site to forward requests for static pages to blob storage using a redirect rule. Then the static content will be stored in and served from blob storage.
Place the following in a file named web.config (or modify your existing web.config) and put the web.config in the folder site/wwwroot on your website, next to the site content.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="static" stopProcessing="true">
<match url="static/(.*)" />
<action type="Rewrite" url="https://blobtest.blob.core.windows.net/static/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Better late than never. Azure Blob requires the host header to be set correctly also otherwise it'll 404.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="static" stopProcessing="true">
<match url="static/(.*)" />
<action type="Rewrite" url="https://blobtest.blob.core.windows.net/static/{R:1}" />
<serverVariables>
<set name="HTTP_HOST" value="blobtest.blob.core.windows.net" />
</serverVariables>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Please remember to Allow Server Variable {HTTP_HOST} in URL rewrite.
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/setting-http-request-headers-and-iis-server-variables
You could also set this in applicationhost.config section.
<location path="Default Web Site">
<system.webServer>
<rewrite>
<allowedServerVariables>
<add name="HTTP_HOST" />
</allowedServerVariables>
</rewrite>
</system.webServer>
</location>
I am sorry if it is something novice or silly but this is my first time using a web.config file.
I have been dealing with the pleasure of godaddy not provide svg support by default. So I found some info on using a web.config file to inform the browser what to do with this file type.
Sources
Link 1
Link 2
Link 3
I am able to get the file in the server without crashing everything. The website will still display instead of displaying a 500 (internal) error but the svg still does nothing.
Here is my web.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".svg" />
<mimeMap fileExtension=".svg" mimeType="images/svg+xml" />
<remove fileExtension=".svgz" />
<mimeMap fileExtension=".svgz" mimeType="images/svg+xml" />
</staticContent>
</system.webServer>
</configuration>
Does anyone know what I am doing wrong? I also put the file into the main root file on the server but no luck.
Live site if it helps: Mobile app design
It appears your mimeType is incorrect. Remove the "s" from the images:
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
reference, if you like documentation