MVC 5 Custom Membership Provider Configuration - asp.net-mvc-5

I am trying to migrate an ASP.NET application to MVC 5. The final piece to migrate is the membership provider. I am unable to configure the application to access the existing membership provider.
I started by looking at the documentation at MSDN's Sample Membership Provider Implementation. This leads me to enter the following in my Web.config:
<membership defaultProvider="MyMembershipProvider">
<providers>
<clear />
<add
name="MyMembershipProvider"
type="my.namespace.MyMembershipProvider, my.package.name"
connectionStringName="MyServiceContext"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
writeExceptionsToEventLog="true"
/>
</providers>
</membership>
<roleManager defaultProvider="MyRoleProvider">
<providers>
<clear />
<add
name="MyRoleProvider"
type="my.namespace.MyRoleProvider, my.package.name"
/>
</providers>
</roleManager>
When I try to run the application, I get the following error:
The configuration section 'membership' cannot be read because it is missing a section declaration
What might I be doing wrong?

D'oh!
Turns out I had put the <membership> tag inside the top-level <configuration> section, but it belongs inside <system.web>:
<configuration>
... stuff ...
<system.web>
<membership ...>
... stuff from question description ...
</membership>
<roleManager ...>
... stuff from question description ...
</roleManager>
</system.web>
</configuration>
Changing the location in the file fixed the error.

Related

Asp.Net Core 2 (full framework) deployment to IIS creates an unwanted folder on the disk root

I have deployed a Asp.Net Core 2 app to IIS. The app is running fine but it keeps creating the following directory structure in the disk root:
D:\MYAPPNAME\MYAPPNAME\1.0.0
Even if i manually delete the folder, it gets created again when the app runs. What may cause this behaviour?
EDIT
After further investigation, i reproduced the issue using the VS 2017 template for asp-net core2 mvc application.
After adding Microsoft.Extensions.Logging.TraceSource nuget package and configuring the logs in app.config the unwated folder gets created...
This is the relevant part of the App.config
<system.diagnostics>
<sources>
<source name="TestApp" switchValue="All">
<listeners>
<clear />
<add name="RotatingFileLog" />
</listeners>
</source>
<source name="Microsoft" switchValue="All">
<listeners>
<clear />
<add name="RotatingFileLog" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="RotatingFileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" logFileCreationSchedule="Daily" traceOutputOptions="DateTime" BaseFileName="test" location="Custom" CustomLocation="E:\logs\test\" Delimiter="|" AutoFlush="True" Append="True"></add>
</sharedListeners>
<trace autoflush="true" indentsize="4">
<listeners>
<clear />
<add name="RotatingFileLog" />
</listeners>
</trace>
</system.diagnostics>
It has turned out that Microsoft.VisualBasic.Logging.FileLogTraceListener was creating the folder. I switched to another listener, in this case Essential.Diagnostics.RollingFileTraceListener

500 Error on AppHarbor but downloaded build works on my machine

I'm using Visual Studio 2013 on Windows 8. I have a web service built off ServiceStack. Everything works fine on my machine but when deploying it to AppHarbor I get a 500 error. I set customErrors mode="off" and I still get a 500 error with no stack trace.
According to AppHarbor's FAQ:
If enabling Custom Errors doesn't produce a stacktrace, then that's indicative of a configuration problem that prevents the ASP.NET runtime from initializing. You can debug such problems by deploying your app (either built locally or build output downloaded from AppHarbor) to a full IIS running on your local machine. You must configure the application pool to run in Integrated Pipeline mode to properly replicate AppHarbor's environment.
So I did this. I downloaded the build output from AppHarbor and ran it on my local IIS and it worked fine!
The AppHarbor Errors page says
No errors to display.
And a AppHarbor's log session feature displays no meaningful information:
2013-12-31T09:55:20.886+00:00 appharbor web.1 Created new worker (version 1388526921)
2013-12-31T09:55:24.864+00:00 appharbor web.1 Warming up (version 1388526921)
2013-12-31T09:55:32.134+00:00 appharbor web.1 Web worker root URL returned HTTP status code 500 (Internal Server Error) (version 1388526921)
Any suggestions?
--
for references, here's an outline of my web.config:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth">
<section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth" requirePermission="false" allowLocation="true" />
<section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth" requirePermission="false" allowLocation="true" />
<section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth" requirePermission="false" allowLocation="true" />
<section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth" requirePermission="false" allowLocation="true" />
</sectionGroup>
</configSections>
<appSettings>
....
</appSettings>
<connectionStrings>
....
</connectionStrings>
<system.web>
<customErrors mode="Off">
</customErrors>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers>
<compilation debug="true" />
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
<directoryBrowse enabled="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="MongoDB.Driver" publicKeyToken="f686731cfb9cc103" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.8.2.34" newVersion="1.8.2.34" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MongoDB.Bson" publicKeyToken="f686731cfb9cc103" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.8.2.34" newVersion="1.8.2.34" />
</dependentAssembly>
</assemblyBinding>
<!-- This prevents the Windows Event Log from frequently logging that HMAC1 is being used (when the other party needs it). -->
<legacyHMACWarning enabled="0" />
</runtime>
<uri>
<!-- The uri section is necessary to turn on .NET 3.5 support for IDN (international domain names),
which is necessary for OpenID urls with unicode characters in the domain/host name.
It is also required to put the Uri class into RFC 3986 escaping mode, which OpenID and OAuth require. -->
<idn enabled="All" />
<iriParsing enabled="true" />
</uri>
<system.net>
<defaultProxy enabled="true" />
<settings>
</settings>
</system.net>
<dotNetOpenAuth>
<!-- This is an optional configuration section where aspects of dotnetopenauth can be customized. -->
<!-- For a complete set of configuration options see http://www.dotnetopenauth.net/developers/code-snippets/configuration-options/ -->
<openid>
<relyingParty>
<security requireSsl="false">
</security>
<behaviors>
<!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
with OPs that use Attribute Exchange (in various formats). -->
<add type="DotNetOpenAuth.OpenId.RelyingParty.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
</relyingParty>
</openid>
<messaging>
<untrustedWebRequest>
<whitelistHosts>
</whitelistHosts>
</untrustedWebRequest>
</messaging>
<!-- Allow DotNetOpenAuth to publish usage statistics to library authors to improve the library. -->
<reporting enabled="true" />
</dotNetOpenAuth>
</configuration>
Just a wild guess: (not much to go on) but I have had similar problems when, for example, I was using the IIS rewrite module on my local machine (and it worked fine), but when I uploaded to a host that did not have that add-on module installed, I would get a 500 error with very little to go on - sounds similar. It drove me crazy trying to find it.
So make sure whatever options/addons that you might have and be using locally in IIS are also installed on the host.
Similarly, make sure you understand everything that is being referenced/used in your web.config - that is likely the problem area.

Why does a deployed Empty MVC4 project have errors and references to DefaultConnection Strings?

I can create an Empty MVC4 project in Visual Studio 2012. Add a simple controller and view, then deploy to Azure. Opening the website from Azure produces an error:
Connection string "DefaultConnection" was not found.
Line 2: if (!WebSecurity.Initialized)
Line 3: {
Line 4: WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId",
Line 5: "UserName", autoCreateTables: true);
Line 6: }
Source File: c:\DWASFiles\sites\pre\VirtualDirectory0\site\wwwroot\_AppStart.cshtml Line: 4
Why is an Empty Project trying to reference Websecurity/Database/etc.?
Why can't I find this code any where in my project with a global search?
Any help would be extremely appreciated. I'm losing my mind I think.
It seems your test website is inheriting membership provider from machine.config. Try adding this elements to your <system.web> element in web.config
<membership>
<providers>
<clear />
</providers>
</membership>
<roleManager enabled="false">
<providers>
<clear />
</providers>
</roleManager>
<profile enabled="false">
<providers>
<clear />
</providers>
</profile>
also add this:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="RoleManager" />
</modules>
</system.webServer>
I found the problem. I had some files in the root from a previous deployment that weren't being removed when I deployed. Completely not code related.

Error on trying to configure RavenDB in IIS mode

Following the steps in this tutorial, the first item of "Setting up with IIS 7.5" after clicking on "Modules" in inetmgr, the following error occurs:
Full image: http://i.stack.imgur.com/QCM4s.png
Web.config in RavenDB
<configuration>
<appSettings>
<add key="Raven/DataDir" value="~\Data"/>
<add key="Raven/AnonymousAccess" value="Get"/>
</appSettings>
<system.webServer>
<handlers>
<add name="All" path="*" verb="*" type="Raven.Web.ForwardToRavenRespondersFactory, Raven.Web"/>
</handlers>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
</system.webServer>
<runtime>
<loadFromRemoteSources enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Analyzers"/>
</assemblyBinding>
</runtime>
</configuration>
applicationHost.config
http://pastebin.com/UJTJfB9f
Try
For a few attempts, I tried to change
this..
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
to this..
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
Results
When trying to access "in inetmgr Modules worked!"
However RavenDB Studio does not work.
The following image:
Config Error
This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File
\\?\C:\Users\Riderman\RavenDB-Build-960\Web\web.config
Check your server web.config and change overrideModeDefault from Deny to Allow.
<configSections>
<sectionGroup name="system.webServer">
<section name="handlers" overrideModeDefault="Deny" />
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
You can also manage sections on web server level (just select the Server in the left pane) in your IIS management console and then select "Feature Delegation":
As you see in the picture above all the features are Read/Write. Currently on my machine the Modules feature is Read Only, so I'd need to change it to Read/Write - in the right hand pane in Set Feature Delegation just click on Read/Write...

ASP.NET MVC 2 & IIS : HTTP 500.24 favicon.ico Error

I have a little weird behavior with my ASP.NET MVC 2 application.
I'm using IIS 7.5, Windows Authentication and ASP.NET Impersonation for my webpage to load.
After several searches, I didn't found a nice way to get rid of the 500.24 Request that I keep getting on every page load (The favicon.ico at the root directory triggers this) :
I've looked at some articles like this one or that one but this doesn't seems to solve my issue. I need these settings on for my application to work here : .NET 4 Framework Integrated Mode pipeline, Windows Authentification and ASP.NET Impersonation.
Here's a simplified version of my web.config, if it can help anyone (of course, I've removed the connections strings for security reasons..)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="Off" />
<identity impersonate="true" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Windows">
<!-- roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider" / -->
<!-- forms loginUrl="~/Account/LogOn" timeout="2880" / -->
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/Globe" />
</providers>
</membership>
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/Globe" />
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear />
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/Globe" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/Globe" />
</providers>
</roleManager>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=edge" />
</customHeaders>
</httpProtocol>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<security>
<requestFiltering>
<verbs>
<add verb="PUT" allowed="true" />
<add verb="DELETE" allowed="true" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
</configuration>
My application IS working, the favicon.ico IS loading, I'm just wondering why it does fires a 500.24 on every request (Of course, maybe it's Fiddler who can't authenticate itself and causes de 500.24 HTTP Error, but when it does normally it triggers a 401.2 - Unauthorized instead...)
My guess is that favicon.ico is either running in a different application pool, or there is a web.config in the root of the site that has issues.
So:
1) Check to see if the root of the site (the directory where /favicon.ico lives) includes a web.config. If it does, then check to see if it is setting a system.web/httpModule, or httpHandler, or system.web/identity (impersonate) or something like that, and the application pool is running in integrated mode.
So what you need to do is either remove the offending httpmodule/httphandler/impersonate setting, or change the application pool to run as classic, or add the same configuration your site includes which is <validation validateIntegratedModeConfiguration="false" />
What CarlosAg said. Cheap fix might be to move the favicon into the offended app rather than barking up the tree.
I did find the answer to my problem =)
You're gonna laugh at me, for sure.. =P
Well, part of the answer is the <validation validateIntegratedModeConfiguration="false" /> in the C:\inetpub\wwwroot that CarlosAg pointed out, but the other part was that I simply forgot to add the <link rel="icon" href="<%: Url.Content("~/favicon.ico")%>" type="image/x-icon" /> to my Site.Master file in my ASP.NET MVC 2 Application. Since Chrome and IE does look at the root directory for a favicon.ico, it appeared to work, but I didn't notice until now that Firefox wasn't loading up the favicon.
Now the favicon loads on every browser, and there is no 500.24 HTTP Request sent over in Fiddler.
Thanks ! =)

Resources