MvcSiteMapProvider and web.config: Parser Error Message: Value cannot be null - asp.net-mvc-3

In my web.config file I have:
<siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
<providers>
<clear />
<add name="MvcSiteMapProvider"
type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
siteMapFile="~/Mvc.Sitemap"
securityTrimmingEnabled="true"
cacheDuration="5"
enableLocalization="false"
scanAssembliesForSiteMapNodes="true"
excludeAssembliesForScan=""
includeAssembliesForScan=""
attributesToIgnore=""
nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider"
controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider"
actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider"
aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider"
siteMapNodeUrlResolver="MvcSiteMapProvider.DefaultSiteMapNodeUrlResolver, MvcSiteMapProvider"
siteMapNodeVisibilityProvider="ekmProspector.web.SiteMapProviders.AuthenticatedVisibilityProvider, ekmProspector"
siteMapProviderEventHandler="MvcSiteMapProvider.DefaultSiteMapProviderEventHandler, MvcSiteMapProvider"
/>
</providers>
</siteMap>
I also have project reference to the MvcSiteMap library dll, a sitemap named mvc.sitemap.
The pages namespaces also look like:
<pages>
<namespaces>
...
<add namespace="MvcSiteMapProvider.Web.Html"/>
<add namespace="MvcSiteMapProvider.Web.Html.Models"/>
</namespaces>
</pages>
However, whenever I browse to any page in my MVC3 project I get the following error:
Configuration Error Description: An
error occurred during the processing
of a configuration file required to
service this request. Please review
the specific error details below and
modify your configuration file
appropriately.
Parser Error Message: Value cannot be
null. Parameter name: type
And the source error is pointing to this line:
Line 91: <clear />
Line 92: <add name="MvcSiteMapProvider"
Line 93: type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
Why am I getting this error?

I eventually found out myself what the problem was. The MvcSiteMap provider library uses the reflection Activator.Createinstance() method to call into the provider you set-up in the sitemap file. If the format of the provider is incorrect, Activator fails with the above message.
For example, the value in the sitemap for a visibilityprovider should be "fullqualifiednamespace.ProviderClass, AssemblyName".
e.g. "MyApplicationNamespace.AuthenticationVisibilityProvider, MyApplication"

Related

SQL SERVER with VS2010 Login

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source="Localhost\SQLEXPRESS";
Initial Catalog=Saqib;Integrated Security=SSPI;
AttachDBFilename=|D:\SAQIB|\aspnetdb.mdf;
User Instance=true; User ID=sa;Password=angel"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" 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="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I create a connectionstring to access localhost database. My code is below please suggest me that is it correct or not? Because when I run my login page on the browser it give this error:
Server Error in '/SAQIB1' Application.
Invalid value for key 'attachdbfilename'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Invalid value for key 'attachdbfilename'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Usually when you specify the db filename, you would use the |DataDirectory| placeholder. Its a substitution string used to denote the location of your db file like so:
"AttachDBFilename=|DataDirectory|database.mdf;"
In your case, you are specifying your own value and not using DataDirectory, so exclude the | characters and your setting would be:
AttachDBFilename=D:\SAQIB\aspnetdb.mdf;

MVC 4 installation resulting in Exception has been thrown by the target of an invocation

I have an MVC 3 application that uses a Custom Role provider.
public class MyRoleProvider : System.Web.Security.RoleProvider
I have this setup in the web.config as follows
<roleManager defaultProvider="MyRoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear />
<add name="MyRoleProvider" type="Namespace.MyRoleProvider, NameSpace" connectionStringName="MembershipDBConnStrName" />
</providers>
</roleManager>
This was all working fine until, well I decided to install MVC 4 to playaround with it.
Now my mvc 3 app is not loading with a configuration error that points to my custom role provider
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Exception has been thrown by the target of an invocation.
Line 81: <providers>
Line 82: <clear />
Line 83: **<add name="MyRoleProvider" type="Namespace.MyRoleProvider, Namespace" connectionStringName="MembershipDBConnStrName" />**
Line 84: </providers>
Line 85: </roleManager>
Doing some reading I see some huge changes around membership (namely the simplemembership provider) but I am hoping there is a quick fix for my stuff to continue to work.
Try delete all constructors from "MyRoleProvider" class.

MVC3 web app / tutorial won't "log in" using ASPNETDB.mdf on IIS7 webserver

I have just uploaded my MVC3 ASP.net web application to my server 2008 R2 IIS 7.5 Express webserver.
The web app loads fine, but when clicking on the logon link and either trying to register a user account or log a existing user account on I get the following error:
"Sorry, an error occurred while processing your request."
If I browse the web app on my webserver (from within IIS7.5) and try the logon link I get the following ASP error:
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
"Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code."
"Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
"Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below."
Would someone mind helping me trouble shoot please?
I have two databases configured in my Web.Config:
<connectionStrings>
<add name="DatabaseDBContext" connectionString="data source=|DataDirectory|Content_Database.sdf" providerName="System.Data.SqlServerCe.4.0"/>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
The SQL Compact (Content_Database.sdf) database works fine. I only get the error when trying to access the aspnetdb.mdf database.
The ASPNETDB.mdf database is practically in identical state to what you get given when loading the Microsoft MVC3 Razor template / tutorial from Visual Web Developer Express 2010.
I tried installing SQL Express 2008 on my webserver just in case this was the issue, made no difference.
The whole web application works perfectly on my Visual Web Developer 2010 Express development server (I can create users and log them on and off successfully). It just fails as soon as it is uploaded to the webserver.
Help appreciated - many thanks :-)
Full Web.Config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<connectionStrings>
<add name="DatabaseDBContext" connectionString="data source=|DataDirectory|\Content_Database.sdf" />
<add name="ApplicationServices" connectionString="data source=|DataDirectory|\aspnetdb.sdf" />
<!--<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />-->
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<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.Helpers, Version=1.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=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Admin/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="SqlCeMembershipProvider" type="Project1.Domain.SqlCeMembershipProvider" connectionStringName="ApplicationServices" applicationName="/"
enablePasswordRetrieval="false" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" writeExceptionsToEventLog="false" />
<!--<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="/" />-->
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<roleManager defaultProvider="SqlCeRoleProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All">
<providers>
<clear/>
<add name="SqlCeRoleProvider" type="System.Web.Security.SqlCeRoleProvider" connectionStringName="ApplicationServices" applicationName="/" writeExceptionsToEventLog="true" />
<!--<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.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</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-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration
>
It looks like your DatabaseDBContext/SDF if a Sql Compact database. This engine is extremely different from an administrators point of view. Basically, it is very simple to setup and get working.
Your ApplicationServices/mdf file is not a Compact database, it uses the normal sql (express, dev, workgroup, standard, enterprise etc) engine. This does require a bit of tweaking to get working. Your data source= option is configuring the SqlClient to use a specific engine installed on the local machine to open the database (this would require sql to be installed on the local machine as an instanced install with the name SqlExpress) and properly configured to allow connections (possibly remote). The Integrated Security is configuring the SqlClient to connect to the server as the user configued in the AppPool to connect to the database, which requires that user to have access to the file where the database is stored, the database itself (inside as security), and all the other security requirements of SSPI (which I would highly recommend you keep).
Update
I have a few projects running exclusively on Compact Framework (because for small projects, it's so much easier to maintain/administer).
To use SQL Server Compact 4, you need to install the Visual Studio Tools for SQL Server Compact 4. I use erikej SQL Compact Providers (Membership and Role) for asp.net and haven't run into any issues. The nice part about the providers is that most of the code you've written against the current providers won't change, you're just replacing the provider and database.
Either way, happy coding!
Update 2
My web.config has the following entries:
<connectionStrings>
<add name="membershipDatabase"
connectionString="data source=|DataDirectory|\Membership.sdf" />
</connectionStrings>
<membership defaultProvider="SqlCeMembershipProvider">
<providers>
<clear />
<add name="SqlCeMembershipProvider"
type="Project1.Domain.SqlCeMembershipProvider"
connectionStringName="membershipDatabase"
applicationName="/"
enablePasswordRetrieval="false"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
passwordFormat="Hashed"
writeExceptionsToEventLog="false" />
</providers>
</membership>
<roleManager defaultProvider="SqlCeRoleProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All">
<providers>
<clear />
<add name="SqlCeRoleProvider"
type="Project1.Domain.SqlCeRoleProvider"
connectionStringName="membershipDatabase"
applicationName="/"
writeExceptionsToEventLog="true" />
</providers>
</roleManager>

Using System.Web.Providers with Sql Compact

Following the article shanselman i'm trying to use "System.Web.Providers" so you can use memberships, rules and profiles with Sql Server Compact.
I installed via Nuget, created a Users.sdf database and copied to the App_Data folder.
My Web.config was as follows:
<profile defaultProvider="DefaultProfileProvider">
<providers>
<clear />
<add
name="DefaultProfileProvider"
type="System.Web.Providers.DefaultProfileProvider"
connectionStringName="DefaultConnection"
applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<clear />
<add connectionStringName="DefaultConnection" enablePasswordRetrieval="false"
enablePasswordReset="true" requiresQuestionAndAnswer="false"
requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<clear />
<add connectionStringName="DefaultConnection" applicationName="/"
name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider" />
</providers>
</roleManager>
<sessionState mode="Custom" customProvider="DefaultSessionProvider">
<providers>
<add
name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider"
connectionStringName="DefaultConnection"
applicationName="/" />
</providers>
</sessionState>
<connectionStrings>
<add name="Sql_CE" connectionString="Data Source=|DataDirectory|\Users.sdf;"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
I can not use "aspnet_regsql" because it generates the tables to a SQL Server based
The following error occurs when trying to access the "Web Site Administration Tool" on page security
There is a problem with your selected
data store. This can be caused by an
invalid server name or credentials, or
by insufficient permission. It can
also be caused by the role manager
feature not being enabled. Click the
button below to be redirected to a
page where you can choose a new data
store.
The following message may help in
diagnosing the problem: The
pre-application start initialization
method Start on type
WebMatrix.WebData.PreApplicationStartCode
threw an exception with the following
error message: This method cannot be
called during the application's
pre-start initialization stage.
First rename your connection string to DefaultConnection and remove the \ in front of Users.sdf like so:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=|DataDirectory|Users.sdf;"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
You say that you
created a Users.sdf database
how? The Providers framework and SqlCe should do this for you. Try deleting the Users.sdf from the App_Data folder and try accessing the "Web Site Administration Tool" again. The provider engine should recreate it for you.

SiteMap and multiple providers

I have several sitemap providers(default, admin, etc) and run into a problem when I am using the admin provider. The root node always shows the home page of the default provider instead of the admin provider. Any ideas why and how this can be fixed?
<siteMap defaultProvider="default" enabled="true">
<providers>
<clear/>
<add name="default"
description="Default SiteMap provider."
type="BLL.CustomSiteMapProvider"
siteMapFile="~/Web.sitemap"
securityTrimmingEnabled="true" />
<add name="AdminXmlSiteMapProvider"
description="Admin SiteMap provider."
type="BLL.CustomSiteMapProvider"
siteMapFile="~/admin/admin.sitemap"
securityTrimmingEnabled="true" />
<add name="FooterXmlSiteMapProvider"
description="Footer SiteMap provider."
type="BLL.CustomSiteMapProvider"
siteMapFile="footer.sitemap"
securityTrimmingEnabled="true" />
</providers>
</siteMap>

Resources