Pages

Monday, August 23, 2010

ASP.NET User Profiles.

It totally sucks.
Membership data in the ASP.NET database stores user names, emails, and a little other information, but I need to add more... All I want is a few additional columns added to the user's data, like their real name, phone/fax/cell numbers, etc. I don't want to go to the trouble of creating a SQL Server table and managing all the relationships to do this and then creating the SQL to fish that all up in my code.
Well, as it turns out that's exactly what the ProfileCommon object does.
There are a number of uncommonly pleasant surprises when you dig into this feature, so let's get started!
This article assumes you're using an aspnet default database setup created as in this article.
Ok try this: In your code pages, type Profile.: you will see a hint showing the options available.
Profile Context Help
yes you can stretch the pop-up box!
Now, open your web.config file. Look for the end of the system.web section. Insert the following lines.
<profile defaultProvider="ProfileProvider">
            <providers>
                <clear/>
                <add connectionStringName="ConnectionString" applicationName="/" name="ProfileProvider" type="System.Web.Profile.SqlProfileProvider"/>
            </providers>
            <properties>
                <add name="email_verified" allowAnonymous="false" type="System.Boolean"/>
                <add name="subscribed" allowAnonymous="false" type="System.Boolean"/>
                <add name="MemberID" allowAnonymous="false" type="System.String"/>
                <add name="FullName" allowAnonymous="false" type="System.String"/>
            </properties>
        </profile>
OK, obviously your connection string has to be changed to match the one in your Membership and Roles provider. Look at the profile section. The editor doesn't help much with creating these types, but they are not hard to figure out.
All you need to do is create whatever columns you want to add. Then once they are added here, go back to your C# code and type Profile. again.

Notice that the added properties are now available to you to use in your programming. You can display then onscreen, let people edit them, even modify them in your code.


The Profile object is of type ProfileCommon, and is automatically instantiated when your page is loaded. Here are a few shortcuts for using it.


Use the logged-in user's Profile Profile.[fieldname]
Look up another user's Profile ProfileCommon otherProfile = Profile.GetProfile(otherUSerName);

Tuesday, August 10, 2010

Server Application Unavailable

I fought this for a week - there was so much junk info out there.  My system config is as follows:
  • Windows SBS 2003 SP2 
  • IIS 6
  • Hosting a mix of ASP.NET 2.0, 2.5, 3.5 sites
When I added my first Visual Web Developer 2010 site using the .net 4.0 framework, These errors happened.

Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request.
Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.
...and in the Application event Log...


Event Type:    Error
Event Source:    ASP.NET 4.0.30319.0
Event Category:    None
Event ID:    1007
Date:        8/4/2010
Time:        3:34:08 PM
User:        N/A
Computer:    WEB1
Description:
aspnet_wp.exe could not be launched because the username and/or password supplied in the processModel section of the config file are invalid.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

OMG this was so easy.
On the Web Server...
  1. open the C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Config folder. 
  2. Edit Machine.config.
  3. in the  <system.web></system.web> section, change <processModel autoConfig="true"> to <processModel username="SYSTEM"></processModel>
  4. Save and exit.
  5. open a command window and enter IISRESET.
  6. Your web site should now work.

Tuesday, August 3, 2010

HTML Dropdown for all US and Canada States/Provinces

<SELECT NAME="state" SIZE=1>
                <OPTION VALUE="United States" disabled="disabled">United States</option>
                <OPTION VALUE="AL - Alabama">Alabama</option>
                <OPTION VALUE="AK - Alaska">Alaska</option>
                <OPTION VALUE="AZ - Arizona">Arizona</option>
                <OPTION VALUE="AR - Arkansas">Arkansas</option>
                <OPTION VALUE="CA - California" SELECTED>California</option>
                <OPTION VALUE="CO - Colorado">Colorado</option>
                <OPTION VALUE="CT - Connecticut">Connecticut</option>
                <OPTION VALUE="DE - Delaware">Delaware</option>
                <OPTION VALUE="DC - Dist of Columbia">District of Columbia</option>
                <OPTION VALUE="FL - Florida">Florida</option>
                <OPTION VALUE="GA - Georgia ">Georgia</option>
                <OPTION VALUE="HI - Hawaii">Hawaii</option>
                <OPTION VALUE="ID - Idaho">Idaho</option>
                <OPTION VALUE="IL - Illinois">Illinois</option>
                <OPTION VALUE="IN - Indiana">Indiana</option>
                <OPTION VALUE="IA - Iowa">Iowa</option>
                <OPTION VALUE="KS - Kansas">Kansas</option>
                <OPTION VALUE="KY - Kentucky">Kentucky</option>
                <OPTION VALUE="LA - Louisiana">Louisiana</option>
                <OPTION VALUE="ME - Maine">Maine</option>
                <OPTION VALUE="MD - Maryland">Maryland</option>
                <OPTION VALUE="MA - Massachusetts">Massachusetts</option>
                <OPTION VALUE="MI - Michigan">Michigan</option>
                <OPTION VALUE="MN - Minnesota">Minnesota</option>
                <OPTION VALUE="MS - Mississippi">Mississippi</option>
                <OPTION VALUE="MO - Missouri">Missouri</option>
                <OPTION VALUE="MT - Montana">Montana</option>
                <OPTION VALUE="NE - Nebraska">Nebraska</option>
                <OPTION VALUE="NV - Nevada">Nevada</option>
                <OPTION VALUE="NH - New Hampshire">New Hampshire</option>
                <OPTION VALUE="NJ - New Jersey">New Jersey</option>
                <OPTION VALUE="NM - New Mexico">New Mexico</option>
                <OPTION VALUE="NY - New York">New York</option>
                <OPTION VALUE="NC - North Carolina">North Carolina</option>
                <OPTION VALUE="ND - North Dakota">North Dakota</option>
                <OPTION VALUE="OH - Ohio">Ohio</option>
                <OPTION VALUE="OK - Oklahoma">Oklahoma</option>
                <OPTION VALUE="OR - Oregon">Oregon</option>
                <OPTION VALUE="PA - Pennsylvania">Pennsylvania</option>
                <OPTION VALUE="RI - Rhode Island">Rhode Island</option>
                <OPTION VALUE="SC - South Carolina">South Carolina</option>
                <OPTION VALUE="SD - South Dakota">South Dakota</option>
                <OPTION VALUE="TN - Tennessee">Tennessee</option>
                <OPTION VALUE="TX - Texas">Texas</option>
                <OPTION VALUE="UT - Utah">Utah</option>
                <OPTION VALUE="VT - Vermont">Vermont</option>
                <OPTION VALUE="VA - Virginia">Virginia</option>
                <OPTION VALUE="WA - Washington">Washington</option>
                <OPTION VALUE="WV - West Virginia">West Virginia</option>
                <OPTION VALUE="WI - Wisconsin">Wisconsin</option>
                <OPTION VALUE="WY - Wyoming">Wyoming</option>
                <OPTION VALUE="GU - Guam">GUAM</option>
                <OPTION VALUE="PR - Puerto Rico">Puerto Rico</option>
                <OPTION VALUE="VI - Virgin Islands">Virgin Islands</option>

                <OPTION VALUE="Canada" disabled="disabled">Canada</option>
                <OPTION VALUE="AB - Alberta">Alberta</option>
                <OPTION VALUE="BC - British Columbia">British Columbia</option>
                <OPTION VALUE="MB - Manitoba">Manitoba</option>
                <OPTION VALUE="NB - New Brunswick">New Brunswick</option>
                <OPTION VALUE="NL - Newfoundland and Labrador">Newfoundland and Labrador</option>
                <OPTION VALUE="NT - Northwest Territories">Northwest Territories</option>
                <OPTION VALUE="NS - Nova Scotia">Nova Scotia</option>
                <OPTION VALUE="NU - Nunavut">Nunavut</option>
                <OPTION VALUE="ON - Ontario">Ontario</option>
                <OPTION VALUE="PE - Prince Edward Island">Prince Edward Island</option>
                <OPTION VALUE="QC - Quebec">Quebec</option>
                <OPTION VALUE="SK - Saskatchewan">Saskatchewan</option>
                <OPTION VALUE="YT - Yukon">Yukon</option>
              </SELECT>

Share This!

Contact Us

Name

Email *

Message *