How to add new custom section definition and its Details - asp.net

I want to add new configuration section definition in <configSections> in my web.config file using the IIS7 Management Console Configuration Editor and generate a script and execute this script in the installation to update the client's production servers.
I was able to add the section definition using the following code:
ServerManager serverManager = new ServerManager();
Configuration config =
serverManager.GetWebConfiguration("Default Web site/upngisintegration");
SectionGroup rootSectionGroup = config.RootSectionGroup;
SectionDefinition logSectiondef =
rootSectionGroup.Sections.Add("loggingConfiguration");
logSectiondef.Type =
#"Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null";
serverManager.CommitChanges();
However, I don't know how to add the configuration detail (see below).
How do I do this?
Section Definition:
<section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=null" />
Section Details:
<loggingConfiguration
name="Logging Application Block"
tracingEnabled="true"
defaultCategory="General">
<listeners>
<add fileName="C:\temp\xxxxx.log" ..snipped for brevity.. />
<add timestampFormat="MM-dd-yyyy HH-mm-ss" ..snipped for brevity... />
</listeners>
<formatters>
<add template="...." ..snipped for brevity.../>
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</add>X
<add switchValue="All" name="Inbound Outbound Trans">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="RollingFile TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>

After couple of days of research i had to do the following steps to generate the required scripts.
Create a custom_schema.xml with the
schema definition for Logging
Application Block(see below) .. it
is a very tedious process
Copy that file C:\Windows\System32\inetsrv\config\schema
Add a Section definition in the
web.config (application's
web.config) manually
Open the IIS7 Console->Click on the
Configuration Editor (Security
group)
Select the above added section (it
should appear in the list -
loggingConfiguration)
It should show you the complete
definition
Edit the required value (funny thing
is we have to edit all the
values,even though you have default
values, otherwise you will get only
the changed values in the script)
You can click on the Generate Script
link
See below for sample custom_schema.xml
--- Logging Application block's Schema details (CUSTOM_schema.xml)
<configSchema>
<sectionSchema name="loggingConfiguration">
<attribute name="name" type="string" />
<attribute name="tracingEnabled" type="bool" defaultValue="true"/>
<attribute name="defaultCategory" type="string" defaultValue="General"/>
<attribute name="type" type="string" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
<element name="listeners">
<collection addElement="add" removeElement="remove" clearElement="clear">
<attribute name="fileName" required="true" type="string" defaultValue="c:\temp\log.log" />
<attribute name="header" required="true" type="string" defaultValue="-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" />
<attribute name="footer" required="true" type="string" defaultValue="-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-" />
<attribute name="formatter" required="true" type="string" defaultValue="Text Formatter" />
<attribute name="listenerDataType" required="true" type="string" defaultValue="LogicaCMG.EnterpriseLibraryExtensions.Logging.Configuration.RollingFileTraceListenerData, LogicaCMG.EnterpriseLibraryExtensions.Logging, Version=0.5.2.0, Culture=neutral, PublicKeyToken=null" />
<attribute name="traceOutputOptions" required="true" type="string" defaultValue="None" />
<attribute name="type" type="string" required="true" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
<attribute name="name" type="string" required="true" defaultValue="RollingFile TraceListener" />
<attribute name="ageThreshold" type="string" required="true" defaultValue="1" />
<attribute name="ageUnit" type="string" required="true" defaultValue="Days" />
<attribute name="sizeThreshold" type="string" required="true" defaultValue="2" />
<attribute name="sizeUnit" type="string" required="true" defaultValue="Megabytes" />
<attribute name="maximumNumberOfLogs" type="string" required="true" defaultValue="20" />
<attribute name="timestampFormat" type="string" required="true" defaultValue="MM-dd-yyyy HH-mm-ss" />
</collection>
</element>
<element name="formatters">
<collection addElement="add" removeElement="remove" clearElement="clear">
<attribute name="template" required="true" type="string" defaultValue="Timestamp:{timestamp(local:F)}
Message: {message}
Category: {category}
Priority: {priority}
Severity: {severity}" />
<attribute name="type" type="string" required="true" defaultValue="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
<attribute name="name" required="true" type="string" defaultValue="Text Formatter" />
</collection>
</element>
<element name="categorySources">
<collection addElement="add" removeElement="remove" clearElement="clear">
<attribute name="switchValue" required="true" type="string" defaultValue="All" />
<attribute name="name" required="true" type="string" defaultValue="General"/>
<element name="listeners">
<collection addElement="add" removeElement="remove" clearElement="clear">
<attribute name="name" required="true" type="string" defaultValue="RollingFile TraceListener"/>
</collection>
</element>
</collection>
</element>
<element name="specialSources">
<element name="allEvents">
<attribute name="switchValue" type="string" defaultValue="All"/>
<attribute name="name" type="string" defaultValue="All Events"/>
</element>
<element name="notProcessed">
<attribute name="switchValue" type="string" defaultValue="All"/>
<attribute name="name" type="string" defaultValue="Unprocessed Category"/>
</element>
<element name="errors">
<attribute name="switchValue" type="string" defaultValue="All"/>
<attribute name="name" type="string" defaultValue="Logging Errors & Warnings"/>
<element name="listeners">
<collection addElement="add" removeElement="remove" clearElement="clear">
<attribute name="name" type="string" defaultValue="RollingFile TraceListener"/>
</collection>
</element>
</element>
</element>
</sectionSchema>
</configSchema>

Related

Prevent Membership Tables From Being Created

I am in the process of converting an old WebForms app that used membership to using Identity.
I have the Identity tables in my SQL server database and I can do the necessary CRUD operations on them.
But, then, once I start my app and I login with one of my users, all of the Membership tables ('UsersInRoles', 'Roles', 'Profiles', 'Memberships', 'Users', and 'Applications') are recreated.
I need to know how to keep those tables from being created (because of our policies), so any help would be appreciated.
Thanks for any help,
Bob
So, I think that have found what is causing it, but I still have no idea what to do about it.
In my web.config, I have the following section:
<profile defaultProvider="ProfileProviderSql" automaticSaveEnabled="true">
<providers>
<clear />
<add name="ProfileProviderSql" connectionStringName="AppServices" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" applicationName="GMSApp" />
</providers>
<properties>
<add name="CurrentAppId" type="string" defaultValue="" />
<add name="ProjectNumber" type="string" defaultValue="" />
<add name="ProjectAdjustmentNumber" type="int" defaultValue="0" />
<add name="Theme" type="string" defaultValue="Pachanga" />
<add name="UserAgencyID" type="int" defaultValue="0" />
<add name="UserFirstName" type="string" defaultValue="" />
<add name="UserLastName" type="string" defaultValue="" />
<add name="UserContactPhone" type="string" defaultValue="" />
<add name="ProjectHeader" type="string" defaultValue="" />
<add name="IsBaselined" type="bool" defaultValue="false" />
</properties>
</profile>
And the tables are being created when a line of code calls:
if (!PageBase.IsBaselined)
My PageBase code for IsBaselined is:
public static bool IsBaselined
{
get { return ((bool)(HttpContext.Current.Profile.GetPropertyValue("IsBaselined"))); }
set { HttpContext.Current.Profile.SetPropertyValue("IsBaselined", value); }
}
So, I assume that the "profile defaultProvider="ProfileProviderSql" is what is causing the tables to be created, but I'm not sure what I should use to keep the functionality but not keep the table creation.
I hope this is a better explanation.

fosrestBundle and SonataUserBundle new fields serilalisation

i'm using the SonataUserBundle extended under src/Application/Sonata/UserBundle and i added some extra fields in src/Application/Sonata/UserBundle/Resources/config/doctrine/User.orm.xml
<entity name="Application\Sonata\UserBundle\Entity\User" table="ez_user">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<many-to-many field="groups" target-entity="Application\Sonata\UserBundle\Entity\Group">
<join-table name="ez_user_group">
<join-columns>
<join-column name="user_id" referenced-column-name="id"/>
</join-columns>
<inverse-join-columns>
<join-column name="group_id" referenced-column-name="id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<many-to-one field="media" target-entity="Application\Sonata\MediaBundle\Entity\Media">
<cascade>
<cascade-all/>
</cascade>
</many-to-one>
<field name="companyName" column="company_name" type="string" length="255" nullable="true" />
<field name="companyPhone" column="company_phone" type="integer" nullable="true" />
</entity>
getter and setter added in src/Application/Sonata/UserBundle/Entity/User.php
my config.yml is like this
fos_user:
db_driver: orm
firewall_name: main
user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
sonata_user:
security_acl: true
manager_type: orm
class:
user: Application\Sonata\UserBundle\Entity\User
group: Application\Sonata\UserBundle\Entity\Group
jms_serializer:
metadata:
directories:
FOSUB:
namespace_prefix: "FOS\\UserBundle"
path: "%kernel.root_dir%/serializer/FOSUserBundle"
app/serializer/FOSUserBundle/Model.User.xml :
<serializer>
<class name="FOS\UserBundle\Model\User" exclusion-policy="all" xml-root-name="user">
<property name="username" type="string" expose="true" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="usernameCanonical" type="string" expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
<property name="email" type="string" expose="true" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="emailCanonical" type="string" expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
<property name="enabled" type="boolean" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="plainPassword" type="string" expose="false" since-version="1.0" groups="sonata_api_write" />
<property name="lastLogin" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
<property name="locked" type="boolean" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="expired" type="boolean" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="expiresAt" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="confirmationToken" type="string" expose="false" since-version="1.0" groups="sonata_api_read,sonata_search" />
<property name="passwordRequestedAt" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="roles" type="array" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="credentialsExpired" type="boolean" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="credentialsExpireAt" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="gender" expose="false" />
<property name="createdAt" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
<property name="updatedAt" type="DateTime" expose="false" since-version="1.0" groups="sonata_api_read,sonata_api_write,sonata_search" />
</class>
the jms section in the config is to hide some properties like (password, salt, etc) from api return data
my probleme is in my api a dan't get the new fields added in SonataUserBundles (media, comanyName)
any idea ?

doctrine2 (xml): in a one-to-many bidirectional relationship, can't get the infers side?

i have Banner and Group entities with xml configs
Banner.xml
<mapped-superclass name="Banner" table="luc_banners"
repository-class="BannerRepository">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="path" column="path" type="string" nullable="true" />
<field name="link" column="link" type="string" nullable="true" />
<field name="position" column="position" type="string" nullable="true" />
<field name="groupId" column="group_id" type="integer" />
<many-to-one field="group" target-entity="Group" inversed-by="banners">
<join-column name="group_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
</many-to-one>
</mapped-superclass>
Group.xml
<mapped-superclass name="Group" table="luc_banners_groups" repository-class="GroupRepository">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="name" column="group_name" type="string" nullable="true" />
<field name="type" column="group_type" type="string" nullable="true" />
<field name="status" column="group_status" type="string" nullable="true" />
<field name="order" column="group_order" type="integer" nullable="true" />
<one-to-many field="banners" target-entity="Banners" mapped-by="group">
<cascade>
<cascade-all />
</cascade>
</one-to-many>
</mapped-superclass>
when trying to get banners form group object i get empty array, and Profiler shows this sql SELECT l0_.group_name AS group_name0, l0_.id AS id4 FROM luc_banners_groups l0_ WHERE l0_.group_status = ? and show not valid entity with this error Banner - The association Banner#group refers to the inverse side field Group#banners which does not exist.
Can you help me with this thing ?
remove <field name="groupId" column="group_id" type="integer" /> from Banner.xml, I think it's overriding the second one..

Doctrine 2 unknown column type requested

I'm trying to update my doctrine schema with the command:
php app/console doctrine:schema:update --force
I'm getting this error:
[Doctrine\DBAL\DBALException]
Unknown column type requested.
I'm getting this error since I've updated the xml mapping of the user entity in the Sonata UserBundle like this:
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Sonata\UserBundle\Entity\User" table="fos_user_user" repository-class="Application\Sonata\UserBundle\Repository\UserRepository">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="name" type="string" length="50" />
<field name="birthdate" type="date" />
<field name="natRanking" type="string" length="10" />
<field name="interNatRanking" type="string" length="10" nullable="true" />
<field name="natDoublesRanking" type="string" length="10" />
<field name="interNatDoublesRanking" type="string" length="10" nullable="true" />
<field name="doublesPartner" type="string" length="50" nullable="true" />
<field name="nationality" type="string" length="50" />
<field name="fileName" type="string" length="255" nullable="true" />
<field name="path" type="string" length="255" nullable="true" />
<field name="file" />
<many-to-many field="teams" target-entity="Tennisconnect\DashboardBundle\Entity\Team" mapped-by="players">
<join-table name="team_user">
<join-columns>
<join-column name="team_id" referenced-column-name="id"/>
</join-columns>
<inverse-join-columns>
<join-column name="user_id" referenced-column-name="id"/>
</inverse-join-columns>
</join-table>
</many-to-many>
<one-to-many field="my_friends" target-entity="Friend" mapped-by="friends_of_mine" />
<one-to-many field="friended_me" target-entity="Friend" mapped-by="friends_with_me" />
</entity>
Is the type of the field "file" missing?

ASP.NET Membership not populating new users

I'm using the ASP.NET Membership provider to handle all membership activities on my current site.
I've run into a weird problem. As you know, if you are familiar with Asp.Net membership, the data is stored in ProfileCommon.
So you could do ProfileCommon.UserId to get the userID.
This all works fine on my production server, my staging server and for old accounts on my local dev server.
However, if I create a new user on my local dev server, the Profilecommon object is not being populated and it is throwing errors because pages reference ProfileCommon.UserId for instance and it's null, thus throwing an exception. The user is Authenticated, but ProfileCommon is not being populated.
Does anyone have any ideas/suggestions as to why this might be happening?
Edit: here's my web.config entry. I'm not sure why we remove AspnetSqlProfileProvider then add it. This is a site I took over and I'm not 100% familiar with asp.net membership yet.
<profile defaultProvider="AspNetSqlProfileProvider">
<providers>
<remove name="AspNetSqlProfileProvider"/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ConnectionString"/>
</providers>
Actual profile info;
<profile defaultProvider="SqlProfileProvider">
<providers>
<remove name="AspNetSqlProfileProvider"/>
<add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="FiftyMillionDBConnection"/>
</providers>
<properties>
<add name="FirstName" type="String" serializeAs="String"/>
<add name="LastName" type="String" serializeAs="String"/>
<add name="EmailAddress" type="String" serializeAs="String"/>
<add name="ScreenName" type="String" serializeAs="String"/>
<add name="BirthDay" type="DateTime" serializeAs="String"/>
<group name="Address">
<add name="AddressLine1" type="String" serializeAs="String"/>
<add name="AddressLine2" type="String" serializeAs="String"/>
<add name="City" type="String" serializeAs="String"/>
<add name="State" type="String" serializeAs="String"/>
<add name="Zip" type="String" serializeAs="String"/>
</group>
<group name="PersonalInfo">
<add name="Gender" type="String" serializeAs="String"/>
<add name="Height" type="String" serializeAs="String"/>
</group>
<group name="OtherInfo">
<add name="Agent" type="String" serializeAs="String"/>
<add name="Employee" type="String" serializeAs="String"/>
<add name="Source" type="String" serializeAs="String"/>
<add name="EventRegistration" type="String" serializeAs="String"/>
</group>
<group name="AuthInfo">
<add name="GUID" type="String" serializeAs="String"/>
<add name="RegSource" type="String" serializeAs="String"/>
<add name="ReceiveMail" type="String" serializeAs="String"/>
</group>
</properties>
</profile>
Thank you!
Is the Profile section in web.config using the same connectionStringName value as the Membership section? This is the first thing I would check.
Edit: Can you post your full profile config block? You should have something that defines the properties like
<profile enabled="true">
<properties>
<add name="UserId" type="Int32"/>
<add name="Gender" type="string"/>
<add name="Age" type="Int32"/>
</properties>
</profile>
In addition to the connectionStringName, you may also want to double-check applicationName. If they don't match, or you define the application name in one section and not the other, you'll run into issues.
<membership defaultProvider="SqlProvider">
<providers>
<add name="SqlProvider"
type="..."
connectionStringName="SomeConnString"
applicationName="SomeApp"
...
... />
</providers>
</membership>
<profile defaultProvider="ProfileProvider">
<providers>
<clear />
<add name="ProfileProvider"
type="..."
applicationName="SomeApp"/>
</providers>
<properties>
...
</properties>
</profile>

Resources