Configure Glimpse in Code - configuration

Glimpse is currently configured in the web config for MVC5 as shown below:
<configuration>
<configSections>
<section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
</configSections>
</configuration>
<system.web>
<httpModules>
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet"/>
</httpModules>
<httpHandlers>
<add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet"/>
</httpHandlers>
</system.web>
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<tabs>
<ignoredTypes>
<add type="{Namespace.Type, AssemblyName}"/>
</ignoredTypes>
</tabs>
</glimpse>
is there anyway to configure glimpse in code perhaps using web activator or a class called from global App Start?

Related

Entity Framework 6 with MySQL - Class Library

I have a project in visual studio (web MVC app) linked to a MySQL database with EF6. Everything is working, I have the provider referenced on web.config, everything is correct. Now I want to separate the Data access to a new project of type class library. I created the project, added the references (MySql.Data and MySql.Data.Entity.EF6), added the provider to the app.config, I think I did all the steps, but I'm stuck when I try to create a new data context with the error below.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="dPhotos.data.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="metadata=res://*/Models.teste.csdl|res://*/Models.teste.ssdl|res://*/Models.teste.msl;provider=MySql.Data.MySqlClient;provider connection string="server=###############;user id=#############;password=############;database=###########"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
</providers>
</entityFramework>
<userSettings>
<dPhotos.data.Properties.Settings>
<setting name="fdsgd" serializeAs="String">
<value>fdgd</value>
</setting>
</dPhotos.data.Properties.Settings>
</userSettings>
</configuration>
Try this:
On your machine where Visual Studio, MySQL VS plugin and Connector/Net are installed:
close all VS instances before doing the steps.
on a Windows Explorer window go to this path or wherever you installed you Connector/NET binaries:
C:\Program Files (x86)\MySQL\MySQL Connector Net {version}\Assemblies\v4.5\
copy the file MySql.Data.Entity.EF6.dll and paste it to this folder:
C:\Program Files (x86)\Microsoft Visual Studio {version}\Common7\IDE\PrivateAssemblies
(if it asks you to overwrite it please do so. You'll need admin rights in order to overwrite the file.)
add reference to this DLL in the project.
Then you can try again to generate the script for your model.
Your app.config should look like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="dPhotosEntities" connectionString="metadata=res://*/Models.dPhotosModel.csdl|res://*/Models.dPhotosModel.ssdl|res://*/Models.dPhotosModel.msl;provider=MySql.Data.MySqlClient;provider connection string="password=######;user id=######;server=######;persistsecurityinfo=True;database=######"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
</configuration>

ASP.NET Razor Site: "This type of page is not served"

I've created an empty ASP.NET website (i.e. razor web pages) but I'm unable to reach the index.cshtml page.
This is true whether I have 'index.cshtml' in the URL or not.
The error pages says:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because
it has been explicitly forbidden. The extension '.cshtml' may be
incorrect. Please review the URL below and make sure that it is
spelled correctly.
Requested URL: /index.cshtml
Here is the entire contents of the web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="webpages:Enabled" value="true"/>
<add key="webpages:Version" value="3.0.0.0"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5" enableVersionHeader="false" requestValidationMode="2.0"/>
<pages validateRequest="false"/>
</system.web>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
<fileExtensions>
<remove fileExtension=".cshtml"/>
<add fileExtension=".cshtml" allowed="true"/>
</fileExtensions>
</requestFiltering>
</security>
<defaultDocument>
<files>
<remove value="index.cshtml"/>
<add value="index.cshtml"/>
</files>
</defaultDocument>
</system.webServer>
</configuration>
Can anyone tell me what I'm missing (or what I've added and which shouldn't be there)?

Linqpad Error with EF DbContext: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

I happily run LinqPad 4.47.02 on a Win7 machine. I tried to add a EF5/dbContext connection. I choose my assembly, the class within the assembly and such assembly's config file. When I add the connection, i get this error:
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw
an exception.
My app.config contains this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
<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="FipavContextContainer" connectionString="metadata=res://*/FipavContext.csdl|res://*/FipavContext.ssdl|res://*/FipavContext.msl;provider=MySql.Data.MySqlClient;provider connection string="server=127.0.0.1;User Id=root;database=fipavmanagerdb"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
I tried to comment the tag in configfile as suggested here but i get the same error.
As a side note, the connection worked and I have many saved linqpad queries. When I try to load and run one of them, linqpad crashes with no additional info.
What am I doing wrong?
Thank you,
F.
(weird) SOLUTION:
I tried moving the <configSections> tag just before <system.data> tag and the error flied away
As per msdn article for configSections element:
If this element is in a configuration file, it must be the first child element of the configuration element
I believe that one of the reasons is that this element defines handlers to handle custom sections in the config so if it is first you don't need to read parse config multiple time to handle a case where a custom section is defined before the handler for this section is defined.

System.Web.Optimization cannot be used in a razor view file in a Class Library project

I am working in a modularized asp.net mvc4 project. Some views are located in a Class Library project. I already set the web.config to enable the intelligence in razor views. The #model, #Html.* and others are all working well. But when I try to reference a js file in my view by using the #Scripts.Render(). It says cannot find "Scripts". I checked the web.config file. The System.Web.Optimization is in the // node. I also installed Microsoft.AspNet.Web.Optimization package by Nuget.
I tried to type the code in a .cs file to use the System.Web.Optimization members, it works. But I cannot do same thing in the .cshtml file. Even when I typing #using System.Web.Optimization, it prompt me the Optimization cannot be found.
I am not sure what else I can do to resolve this issue. Any clues are very appreciated.
If you have a Web.config at the root of the class library, confirm it contains the following: <add namespace="System.Web.Optimization"/>
If you do not, trick Visual Studio into thinking that it is a web project and enable Intellisense and resolve your issue by adding a web.config file to the root of your class library project (the one that contains the Razor views) with the following contents (taken from this blog post) :
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<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" />
</namespaces>
</pages>
</system.web.webPages.razor>
<system.web>
<compilation targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
</system.web>
</configuration>
The above is what worked for me when I faced this issue, but here are more links:
http://forums.asp.net/t/1812274.aspx/1
Getting System.Web.Optimization to work in a razor view within a class library

ASP.NET MVC 2 - Trying to configure role/user management via ASP.NET Configuration Tool

First, my development environment: Win7 laptop with Visual Studio Professional 2010. IIS is NOT installed.
I'm trying to turn on and set up some roles for user management via the ASP.NET Configuration Tool, as demonstrated in the MVCMusicStore tutorial. When I click on the 'Security' tab, I get the following error:
"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: Could not load type 'HandiGamer.MvcApplication'."
When I click on the 'button below', it tells me I'm using AspNetSqlProvider as my provider. When I try to test it, it tells me:
"Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider."
Here's the thing:
The MVCMusicStore demo's role/user management works when I run it through the debugger. I can add myself as a customer, and add/remove items from my cart. Despite this, when I attempt to use the Configuration Tool with it, I get the same errors.
I actually have run aspnet_regsql on my copy of SQL Server 2008 Express. It created the necessary tables for user management. Still didn't fix my problem.
I'm just wondering if I'm missing something obvious, as the tutorial essentially said "Click two buttons and you're all set." It literally said nothing about setting up the db for this.
I'm just stumped at this point. Role/user management works (the MVCMusicStore proves that it does), but the configuration tool won't let me turn it on, set it up, or otherwise edit how it works. It's becoming very frustrating. Any help would be greatly appreciated.
EDIT: My web.config is as follows-
<?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="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="HandiGamer" connectionString="data source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|handigamer.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<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.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<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="HandiGamer" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="HandiGamer" />
</providers>
</profile>
<roleManager enabled="true">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="HandiGamer" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="HandiGamer" />
</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>
<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" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Found the solution. Had to compile/build my solution before the config tool would 'see' the db security stuff.