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

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!

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.

Error 500 adding Entity Framework to web.config on asp.net web api

In an ASP.net 4.5 Web Api, locally and in production environments is working fine.
I added the Nuget package Entity framework 6.1.3 to the solution. Without adding model. Locally with EF it is working, but when I publish to production, it throws "error 500".
EF add lines to the web.config:
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory
type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
In production, when I remove these lines, it works fine (of course without EF).
I tried adding a model then cause the API throws 500.
Is there any way to use EF in this hosting?
Is a problem in the web.config or in the hosting? The api is in a second level directory of a MVC web app.
pd: The hosting uses Managed Pipeline Mode: Integrated.
More info:
When i GET from browser http://max-prueba.somee.com/api/Position/41
it response a status 500 and Server Error
500 - Internal server error. There is a problem with the resource you
are looking for, and it cannot be displayed.
Next step i add line to web config to view description of the error
<customErrors mode="Off"/>
But the response is the same.

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.

'compilerVersion' attribute in the provider options must be 'v4.0' or later

Getting this error:
The value for the 'compilerVersion'
attribute in the provider options must
be 'v4.0' or later if you are
compiling for version 4.0 or later of
the .NET Framework. To compile this
Web application for version 3.5 or
earlier of the .NET Framework, remove
the 'targetFramework' attribute from
the element of the
Web.config file.
It was working on our dev system, and we are now deploying to QA using an xcopy type deploy.
We don't have a "compilerVersion" anywhere in the web.config, and the targetFramework is set to "4.0". We have done an IISReset.
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
UPDATE 2: when we removed the entire section, we got past the error. So my question is, what is wrong with leaving in this section if we are on .NET 4.0?
We just did a full xcopy of exactly what was in Test to QA, and in QA it gets the error and DEV doesn't. So the software and configs are identical. Why would it work on one server and not another? IIS options seem to be identical.
taken from: http://www.asp.net/whitepapers/aspnet4/breaking-changes#0.1__Toc256770150
you should go to your server root web.config and include the whole
<system.codedom>...</system.codedom>
tag content into a
<location path="" inheritInChildApplications="false">...</location>
tag
Possible solution here - asp.net/whitepapers/aspnet4/breaking-changes#0.1__Toc256770150
After fighting with this for a while, I ended up creating a new IIS site using a different port and adding my ASP.Net 3.5 application to the new site and it is working perfectly.
I got the same error and found out that my v4.0 website was hosted under the default website that was v2.0. If you've such setup then you need to remove the following line from your web.config:
<compilation defaultLanguage="c#" debug="true" targetFramework="4.0"/>
I hope that helps.

Tracing is not working on a .NET 2.0 web service

I have a web service written with Visual Studio 2005. My web.config file contains this:
<system.diagnostics>
<trace autoflush="true" indentsize="4" />
</system.diagnostics>
But any call to System.Diagnostics.Trace.WriteLine is ignored. When I step through my code, those lines are skipped over.
Is there another way I should be turning on tracing? How can I tell why tracing is turned off?
I had to add this to my web.config:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp"
extension=".cs"
compilerOptions="/d:TRACE"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="1" />
</compilers>
</system.codedom>
I got that from Microsoft's Troubleshooting Web Services article.