MVC4 Custom 404 page? - web-config

I've place this in web.config <system.webServer>
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" path="/cv/" responseMode="ExecuteURL" />
</httpErrors>
The path that is used temporarily here [myapplication]/cv/ returns a page.
But if I go to [myapplication]/[anything that doesn't exists] to get a 404 response, juste nothing happens.
This is currently working on my old web form site, but I can't get it working on a MVC4 site.
How can I make this work ? (I don't want to use the "Redirect/File" methods)

This is what I have in a current MVC 4 project:
<customErrors mode="On" defaultRedirect="~/Error/General">
<error statusCode="404" redirect="~/Error/Http404" />
</customErrors>
I have an Errors controller, and views for "General" and "Http404" (action methods).
Works like a charm.

Part of the problem might also stem from the fact that the <customErrors> tag is not a valid child of <system.webServer>. Try putting it in <system.web> instead.

Related

Too many redirects ONLY in IOS?

This site works fine everywhere except in IOS.
http://www.pepedivecenter.com.
It works in Windows with Firefox, Chrome or IE.
It works in OSX with Safari or Chrome
It works in Android phones
BUT, it does not work in IOS (iPhone or iPad) using Chrome or Safari!
When I try to open the site in an iPad or an IPhone with Chrome or Safari I get a TOO MANY REDIRECTS error.
The web.config is pretty clean:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="PHP_via_FastCGI" />
<add name="PHP_via_FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\php\php-cgi.exe|-d open_basedir='D:\XVRT\pepedivecenter.com\Html;D:\XVRT\pepedivecenter.com\html\new'" resourceType="File" requireAccess="Script" />
</handlers>
<security>
<ipSecurity allowUnlisted="true">
</ipSecurity>
</security>
<staticContent>
<remove fileExtension=".htm" />
<remove fileExtension=".html" />
<mimeMap fileExtension=".html" mimeType="text/html" />
<mimeMap fileExtension=".htm" mimeType="text/html" />
</staticContent>
</system.webServer>
</configuration>
I tried enabling and disabling the friendly urls,
the site is running under IIS so I tried several configurations with web.config
I cleaned joomla's cache and redirects.
I cleaned the browsers cache and cookies.
I updated everything to the last version (joomla 3.6.5)
but the problem continues.
How can I troubleshoot this problem? any ideas?
tks!
I found a workaround.
The problem was caused by the Joomla plugin "System - Language Filter".
I disabled this plugin and now the site works in IOS.

.net 4.5 web application redirects to ReturnUrl=%2f

I created a web application targeting 4.5.2 framework and using IIS8.
The starting page should be Default.aspx, It used to work OK on framework 3.5 but on framework 4.5.2 it redirects me to Domain\Default.aspx?ReturnUrl=%2f web page even after I've logged in correctly.
I know it can be fixed by adding some code in Global.Application_BeginRequest in Global.asax but I really want to know the real cause of this behaviour and which dll added by .net v4.5 makes this redirect to the root path ?
Well I was trying to fix this loop and it looks it was an authentification issue with .net framework 4.5
you just need to remove the authorize section of the login page in your web config file :
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5">
<buildProviders>
<add extension=".config" type="System.Web.Compilation.IgnoreFileBuildProvider"/>
</buildProviders>
</compilation>
<authentication mode="Forms">
<forms loginUrl="Default.aspx" defaultUrl="yourlink" timeout="60" slidingExpiration="true"/>
</authentication>
<!--<authorization>
<deny users="?"/>
</authorization>-->
Also in section add this key to solve Unobtrusive Validation Mode in ASP.NET 4.5
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
and the loop to root path is gone!

How to deploy different App.config values (with WiX)

I've been looking for a best practice recommendation on how to deploy an application with a WiX installer for different values in its App.config file. For example.
On my local development machine, I use App.config settings for our test environment:
<configuration>
<appSettings>
<WorkingDirectory>C:\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[TestingConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
When I deploy to a test environment, those settings are acceptable. However, when we deploy to a production environment, I'd like them to be different. For example:
<configuration>
<appSettings>
<WorkingDirectory>\\prodserver\Working</WorkingDirectory>
</appSettings>
<connectionStrings>
<add name="ApplicationEntities"
connectionString="[ProductionConnectionString]"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The answer to my question may very well be independent of WiX. But just in case, here is my WiX Product.wxs file's relavent fragment:
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="ProductComponent" Guid="{MY-GUID}">
<File Id="Application.exe"
Name="Application.exe"
Source="..\Application.exe"
Vital="yes"
KeyPath="yes"
DiskId="1" />
<File Id="Application.exe.config"
Name="Application.exe.config"
Source="..\Application.exe.config"
Vital="yes"
KeyPath="no"
DiskId="1" />
</Component>
</ComponentGroup>
</Fragment>
This setup ends with a manual edit of the App.config on the production server, which invites manual error. What would be a better way to handle this to accommodate an automated deployment?
I can think of two options, either deploy the app.config file and edit it using the XmlFile Element, or maintain multiple app.config files each representing your target environment, then deploy the appropriate file.
Here's an exmaple of both options, notice that I copy the file rather than just placing it on the file system. This serves two purposes, firstly you can see by the filename which one has been deployed, secondly if development.app.config and production.app.config are placed in the same location you will get an ICE30 validation error, by copying the file afterwards it avoids this error.
Notice also that I have a condition associated with the component, you'll need to decide how you identify which environment you are deploying to. Some ideas could be to use the machine name, the OU or simply pass it in on the command line as a property.
<Component Id="development.app.config" Guid="*">
<Condition>DEVELOPMENT</Condition>
<File Name="development.app.config" KeyPath="yes">
<CopyFile Id="development.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="C:\Working"
Permanent="no" />
</Component>
<Component Id="production.app.config" Guid="*">
<Condition>PRODUCTION</Condition>
<File Name="production.app.config" KeyPath="yes">
<CopyFile Id="production.app.config" DestinationName="app.config" />
</File>
<util:XmlFile
Id="WorkingDirectory"
Action="setValue"
File="app.config"
ElementPath="/configuration/appSettings"
Name="WorkingDirectory"
Value="\\prodserver\Working"
Permanent="no" />
</Component>

Authentication issue when debugging in VS2013 - iis express

I'm trying to pick up the windows username when debugging in Visual Studio 2013. I am simply using:
httpcontext.current.user.identity.name
If I run this on my Dev Server it works fine, if I run it in debug mode on any previous version of Visual Studio it also works fine.
My problems is - If i run this on visual studio 2013 I get an empty string.
My web config is as follows.
<system.web>
<authentication mode="Windows"/>
<identity impersonate="false"/>
<authorization>
<allow users="*"/>
</authorization>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
I had just upgraded to VS 2013 from VS 2012 and the current user identity (HttpContext.User.Identity) was coming through as anonymous.
I tried changing the IIS express applicationhost.config, no difference.
The solution was to look at the properties of the web project, hit F4 to get the project properties when you have the top level of the project selected. Do not right click on the project and select properties, this is something entirely different.
Change Anonymous Authentication to be Disabled and Windows Authentication to be Enabled.
Works like gravy :)
As I was researching this I found my answer, but can't find the answer on the internet, so I thought I'd share this:
I fixed my issue by modifying my applicationhost.config file. My file was saved in the "\My Documents\IISExpress\config" folder.
It seems that VS2013 was ignoring my web.config file and applying different authentication methods.
I had to modify this portion of the file to look like the below. In truth, I only modified the anonymousAuthentication to be false and the windowsAuthentication mode to true.
<authentication>
<anonymousAuthentication enabled="false" userName="" />
<basicAuthentication enabled="false" />
<clientCertificateMappingAuthentication enabled="false" />
<digestAuthentication enabled="false" />
<iisClientCertificateMappingAuthentication enabled="false">
</iisClientCertificateMappingAuthentication>
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
</authentication>
In Visual Studio 2013 AND VS15 (but i guess if the same for all other version) just press F4 and change this two properties:
-Anonymous Authentication: Disable
-Windows Authentication: Enable
In VS2013 F4 on your project to view properties window and disable Anonymous access and enable "Windows authentication"
Then it will work. No need to change anything else
VS 2015 changes this. It added a .vs folder to my web project and the applicationhost.config was in there. I made the changes suggested (window authentication = true, anon=false) and it started delivering a username instead of a blank.
Open up the applicationHost.config file located in the C:\Users[userid]\Documents\IISExpress\config folder. Inside this file change the overrideModeDefault of anonymousAthentication and windowsAuthentication to "Allow"
<sectionGroup name="security">
<section name="access" overrideModeDefault="Deny" />
<section name="applicationDependencies" overrideModeDefault="Deny" />
<sectionGroup name="authentication">
<section name="anonymousAuthentication" overrideModeDefault="Allow" />
<section name="basicAuthentication" overrideModeDefault="Deny" />
<section name="clientCertificateMappingAuthentication" overrideModeDefault="Deny" />
<section name="digestAuthentication" overrideModeDefault="Deny" />
<section name="iisClientCertificateMappingAuthentication" overrideModeDefault="Deny" />
<section name="windowsAuthentication" overrideModeDefault="Allow" />
</sectionGroup>
Next change lockItem to be "false" for AnonymousAuthenticationModule and WindowsAuthenticationModule
<system.webServer>
<modules>
<!--
<add name="HttpCacheModule" lockItem="true" />
-->
<add name="DynamicCompressionModule" lockItem="true" />
<add name="StaticCompressionModule" lockItem="true" />
<add name="DefaultDocumentModule" lockItem="true" />
<add name="DirectoryListingModule" lockItem="true" />
<add name="IsapiFilterModule" lockItem="true" />
<add name="ProtocolSupportModule" lockItem="true" />
<add name="HttpRedirectionModule" lockItem="true" />
<add name="ServerSideIncludeModule" lockItem="true" />
<add name="StaticFileModule" lockItem="true" />
<add name="AnonymousAuthenticationModule" lockItem="false" />
<add name="CertificateMappingAuthenticationModule" lockItem="true" />
<add name="UrlAuthorizationModule" lockItem="true" />
<add name="BasicAuthenticationModule" lockItem="true" />
<add name="WindowsAuthenticationModule" lockItem="false" />
Making these changes will allow the existing web config settings to override what is in the applicationHost file for IIS Express.
You could also modify the project properties for your web project, choose "Web" from left tabs, then change the Servers drop down to "Local IIS". Create a new virtual directory and use IIS manager to setup your site/app pool as desired.
I prefer this method, as you would typically have a local IIS v-directory (or site) to test locally. You won't affect any other sites this way either.
It appears that the right answer is provided by user3149240 above. However, As Neil Watson pointed out, the applicationhost.config file is at play here.
The changes can actually be made in the VS Property pane or in the file albeit in a different spot. Near the bottom of the applicationhost.config file is a set of location elements. Each app for IIS Express seems to have one of these. Changing the settings in the UI updates this section of the file. So, you can either change the settings through the UI or modify this file.
Here is an example with anonymous auth off and Windows auth on:
<location path="MyApp">
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" />
<anonymousAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>
</location>
This is equivalent in the VS UI to:
Anonymous Authentication: Disabled
Windows Authentication: Enabled
F4 doesn't always bring me to this panel. Besides, it is often said that a picture is worth a thousand words.

Umbraco Custom 404 Error Page Not Working

I am using using Umbraco 4.7 and my server is IIS7 was wondering what is not going right for me. I basically want to make a custom error page (404) and everything I have tried is not working, checked the forums, but it is still showing the same problem.
I have edited my umbracoSettings.config
<errors>
<!-- the id of the page that should be shown if the page is not found -->
<!-- <errorPage culture="default">1647</errorPage> -->
<!-- <errorPage culture="en-US">1647</errorPage> -->
<error404>1647</error404>
</errors>
Also I have looked about saying adding this to the web.config file.
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/error.aspx" responseMode="ExecuteURL" />
</httpErrors>
Any help would highly appreciated. I am a complete novice to IIS and anything involving network settings.
Make sure that 1647 is node id of the 404 page.
Also add the below code in the system.webServer tag in your web.config.
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="400" path="/404" responseMode="ExecuteURL" />
<error statusCode="404" path="/404" responseMode="ExecuteURL" />
</httpErrors>
Hope this works...
Just in case someone stumbles across this like I did when researching a similar problem with Umbraco 7, setting trySkipIisCustomErrors value to true in config/umbracoSettings.config file did it for me.
<web.routing
trySkipIisCustomErrors="true"
internalRedirectPreservesTemplate="false">
</web.routing>
I experienced the same problem, and the solution suggested by Sobin P Samuel worked for me (just copy and paste the httpErrors element directly to the system.webserver section in your Web.Config-file), so I guess this is also what resolved it for paulstewart185...
Please note that according to http://our.umbraco.org/wiki/install-and-setup/configuring-404-pages the solution for IIS 7.5 would be to add the following to the system.webserver section:
<httpErrors existingResponse="PassThrough"/>