views:

98

answers:

1

How do I avoid the same hard-coded string "applicationName="membershipSampleApp" that appears in multiple places in my web.config?

    <membership defaultProvider="AspNetSqlMembershipProvider">
        <providers>
            <clear/>
            <add name="AspNetSqlMembershipProvider"
                 type="System.Web.Security.SqlMembershipProvider"
                 connectionStringName="LocalSqlServer"
                 minRequiredPasswordLength="5"
                 minRequiredNonalphanumericCharacters="0"
                 requiresQuestionAndAnswer="false"
                 ***applicationName="membershipSampleApp"***/>
        </providers>
    </membership>
    <profile>
        <providers>
            <clear/>
            <add name="AspNetSqlProfileProvider"
                 connectionStringName="LocalSqlServer"
                 ***applicationName="membershipSampleApp***"
                 type="System.Web.Profile.SqlProfileProvider"/>
        </providers>
    </profile>
    <roleManager enabled="true"
                 cacheRolesInCookie="true"
                 defaultProvider="AspNetSqlRoleProvider"
                 cookieName=".ASPXROLES"
                 cookiePath="/"
                 cookieTimeout="30"
                 cookieRequireSSL="false"
                 cookieSlidingExpiration="true"
                 createPersistentCookie="false"
                 cookieProtection="All">
        <providers>
            <clear/>
            <add name="AspNetSqlRoleProvider"
                 type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                 connectionStringName="LocalSqlServer"
                 ***applicationName="membershipSampleApp"***/>
        </providers>
    </roleManager>

If there is no such thing, is there a coding alternative to specifying this information in the web.config?

So often, it seems that in ASP.NET things can be done in either "angled brackets" (in the ASP.NET markup or web.config) OR it can be done it the code-behind logic but that people generally prefer the bracket approach. I think that the former creates less flexible and especially SLOPPY hard to read code with limited intellisense.

Can this be done via code? How?

+4  A: 

Unfortunately there is no concept of a variable in a .NET configuration file - you must duplicate that string throughout the file.

Andrew Hare