asp2 roles and membership settings in web.config - asp.net-mvc-2

How can i set up web.config file to support user membership with roles for my mvc page with only database file as i do not have access to sql server at the moment.
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn"
protection="All"
timeout="30"
name="AppNameCookie"
path="~/Account/LogOn"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
cookieless="UseCookies"
enableCrossAppRedirects="false" />
</authentication>
<membership defaultProvider="MyMembershipProvider">
<providers>
<clear/>
<add name="MyMembershipProvider" type="NudaJeFuc.WebUI.Classes.MyMembershipProvider"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" MinRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager>
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</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" />
<add namespace="NudaJeFuc.WebUI.HtmlHelpers"/>
</namespaces>
</pages>

Your web.config looks fine, but you need to set up a connectionString (in your case named ApplicationServices) to point to Sql server that will store membership database.
You can create membership database using a wizard, just run aspnet_regsql from VS cmd. You can read more on MSDN.

Related

If I don't specify the hosting model in web.config, what will be the default process in asp.net core 5.0

This is my web.config file, I am getting 500 exception after I have deployed project in azure server, If I remove V2 in modules application runs, but it runs on kestrel not in IIS.
<configuration>
<location path="." inheritInChildApplications="false">
<!--<system.web>
<httpRuntime maxRequestLength="204800" enableVersionHeader="false" />
</system.web>-->
<system.webServer>
<security>
<!--Removes Server header from response-->
<requestFiltering removeServerHeader="true">
<!--200 MB in bytes-->
<requestLimits maxAllowedContentLength="209715200" maxQueryString="10240" />
</requestFiltering>
</security>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<remove name="X-AspNet-Version" />
<remove name="X-Forwarded-Host" />
<remove name="Server" />
</customHeaders>
</httpProtocol>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Data.WebAPI.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel = "inprocess"/>
</system.webServer>
</location>
</configuration>```

IIS 10 - Windows Authentication - AuthenticationType "unavailable"

I am a web app that I'm trying to get working with Windows Auth. However, no matter what I do, I can't get past a 401.
web.config
<configuration>
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<basicAuthentication enabled="false" />
<windowsAuthentication enabled="true">
<providers>
<clear />
<add value="NTLM" />
</providers>
</windowsAuthentication>
</authentication>
<authorization>
<clear />
<add accessType="Deny" users="?" />
<add accessType="Allow" users="CABLE\mmulhe200" />
</authorization>
</security>
<tracing>
<traceFailedRequests>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Authentication,Security,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket" verbosity="Verbose" />
</traceAreas>
<failureDefinitions timeTaken="00:00:00" statusCodes="401.1" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
</configuration>
IIS Failed Request Trace Output (Partial)
<failedRequest url="http://dev.windowsauthtest.com:80/"
siteId="3"
appPoolId="windowsAuthTest"
processId="33204"
verb="GET"
authenticationType="NOT_AVAILABLE" activityId="{80000727-0003-F400-B63F-84710C7967BB}"
failureReason="STATUS_CODE"
statusCode="401.1"
triggerStatusCode="401.1"
timeTaken="0"
xmlns:freb="http://schemas.microsoft.com/win/2006/06/iis/freb"
>
The part that concerns me is
authenticationType="NOT_AVAILABLE"
I get prompted to enter my credentials and I enter my NT username/password and it just keeps re-prompting.
Any ideas?

Nuget web.config.install.xdt not transforming

I'm having problems figuring out how to transform the web.config file when my NuGet package it installed. It's doing some of the transformations, but not all of them.
Here's the untouched web.config file that I need to modify upon installation of my NuGet package:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<authentication mode="None" /> ***** I want this removed *****
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" /> ***** I want this removed *****
</modules>
</system.webServer>
</configuration>
Here's what I want as the result:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="MvcMailer.BaseURL" value="" />
<add key="SecurityGuardEmailFrom" value="info#email.net" />
<add key="SecurityGuardEmailSubject" value="Your Password has been reset." />
<add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="~/SGAccount/Login" timeout="2880" />
</authentication>
</system.web>
<system.webServer>
<modules>
</modules>
</system.webServer>
</configuration>
This is transformed web.config file in the MVC application, which is incorrect:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="MvcMailer.BaseURL" value="" />
<add key="SecurityGuardEmailFrom" value="info#email.net" />
<add key="SecurityGuardEmailSubject" value="Your Password has been reset." />
<add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" />
</appSettings>
<system.web>
<authentication mode="None" /> ***** Not removed when it should be *****
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
<forms loginUrl="~/SGAccount/Login" timeout="2880" />
</authentication>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" /> ***** Not removed when it should be *****
</modules>
</system.webServer>
</configuration>
And this is my web.config.install.xdt file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<authentication mode="None" xdt:Transform="Remove" xdt:Locator="Match(mode)" />
<authentication mode="Forms" xdt:Transform="Insert">
<forms loginUrl="~/SGAccount/Login" timeout="2880" />
</authentication>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" xdt:Transform="Remove" xdt:Locator="Match(name)" />
</modules>
</system.webServer>
</configuration>
I've read all the documentation on the Nuget.org site about how to use the XDT transformations, and it even works on this tester site; https://webconfigtransformationtester.apphb.com/, but it doesn't work in action.
I'm stumped. Any suggestions on how to make this work?
Here's what the new web.config.install.xdt looks like that handled the job successfully:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="SecurityGuardEmailFrom" value="info#email.net" xdt:Transform="Insert" />
<add key="SecurityGuardEmailSubject" value="Your Password has been reset." xdt:Transform="Insert" />
<add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" xdt:Transform="Insert" />
</appSettings>
<system.web>
<authentication mode="Forms" xdt:Transform="SetAttributes" />
<authentication mode="Forms">
<forms loginUrl="~/SGAccount/Login" timeout="2880" xdt:Transform="Insert" />
</authentication>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" xdt:Transform="Remove" />
</modules>
</system.webServer>
</configuration>
Instead of trying to Remove the original authentication element, I changed the mode attribute, then I Inserted the forms element. The rest seemed to work itself out once this worked correctly.

Issue with configuring web.config to use sql server database

I playing around with the John Papa's HotTowel application. The HotTowel sample uses local codecamper.sdf database and I am trying to configure it to use the database on a sql server 2008 r2. When I run the application, I am getting an error saying "An exception of type 'System.InvalidOperationException' occurred in Breeze.ContextProvider.EF6.dll but was not handled in user code." The error is occurring in the CodeCamperRepository.cs on the line that says "get {return _contextProvider.Metadata()" code. The inner exception says
The connection string 'CodeCamper' in the application's configuration file does not contain the required providerName attribute."
I have the following code in web.config, but I unsure if it is correct:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="CodeCamper" connectionString="Data Source=testdb\cmstest; Integrated Security=True; MultipleActiveResultSets=True" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=testdb\cmstest; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>
Are there any other changes I should look at to make HotTowel connect to Sql Server? what is it that breeze doesn't like about the configuration? Appreciate any insight.
thanks Community
np
Just like the inner exception says: you need the providerName attribute. So change your ConnectionStrings section to:
<connectionStrings>
<add name="CodeCamper" connectionString="Data Source=testdb\cmstest; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Just checking, but do you have the CodeCamper connection reference in your DbContext contstructor?
public CCDbContext()
: base("CodeCamper"){ }

MVC 4 website load shows HTTP Error 500.19

I created a new ASP.NET MVC 4 application based on Internet application template, I could succesfully run it and authenticate user from within VS 2012 Express.
Then published it to a folder in wwwroot, then in IIS 7.5 manager created a virtual directory pointing to that folder, and converted it to an application using a separate 4.0 integrated pool.
When I tried to browse the application from within the IIS manager I get the next error:
HTTP Error 500.19 - Internal Server Error,
The requested page cannot be accessed because the related configuration data for the page is invalid.
Config Error: Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'ExtensionlessUrlHandler-Integrated-4.0'
Config source:
56: <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
57: <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
58: </handlers>
searched here,I found the corresponding answer:
Resolution 1
Delete the malformed XML element from the ApplicationHost.config file or from the Web.config file.
My web.config file is as below:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-digixMVC4-20120915233326;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-digixMVC4-20120915233326.mdf" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="PreserveLoginUrl" value="true"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<!--
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5"/>
</system.Web>
-->
<system.web>
<compilation targetFramework="4.5"/>
<httpRuntime/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880"/>
</authentication>
<pages controlRenderingCompatibilityVersion="4.0">
<namespaces>
<add namespace="System.Web.Helpers"/>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364g85"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364g85"/>
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364g85"/>
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
</entityFramework>
</configuration>
As I am a poorly skilled developer in MVC 4, I would ask if someone could find out the malformed xml element in the file above.
This is true for ASP.NET WebAPI 5.2 too..
I had
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Which I changed to
<add name="ExtensionlessUrlHandler-Integrated-4.0a" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0b" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Thats it.. It worked.
you have the same name in twice. the name must be unique.
current config
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
change to
<add name="ExtensionlessUrlHandler-Integrated-4.0a" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0b" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
I experienced a similar problem to this.
what worked for me was to remove, then re-add the handler:
My guess is that if by default this is enabled in the IIS Server already, it may trigger this error.
I am using IIS 10, MVC 5, .NET Framework 4.6.1
Hope this helps :-)