This tutorial will show you how to enable the configuration settings within the Web.config file for forms authentication, roles, and profile properties for a Windows Application in ASP.NET 3.5 C#.
In this tutorial we will enable the configuration settings within the Web.config file for forms authentication, roles, and profile properties. In order to configure these properties we must first open the Web site’s Web.config file and under the authentication element within the system.web section, change the default windows authentication to use forms:
| <authentication mode="Forms" /> |
Then add the roleManager element to configure the roles services:
| <roleManager enabled="true"/> |
While still in the system.web section, configure the profile serivce through the profile section and its properties element like this example:
| <profile enabled="true"> <properties> <add name="strFirstName" type="String"/> <add name="strLastName" type="String"/> <add name="strPhoneNumber" type="String"/> </properties> </profile> |
As you can see this profile settng defines three properties(strFirstName, strLastName, strPhoneNumber) managed by the ASP.NET profile service. A ProfileCommon class will be created dynammically at runtime by ASP.NET that contains those three properties.
If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!
Now we can create user information that will be used later in this tutorial to log in. In order to create users and assign them profile information, we need to first navigate to the Solution Explorer, select the default.aspx page, Right-click and select view in browser. This should be displayed within the URL:
http://localhost:8080/WebApplicationServices/Default.aspx
Congratulations! Now you are finished creating users, roles, and profile info. Feel free to test the validation controls, add new user, update profile and test all the functionality that we just implemented.
We now have the power to expose the user information that you have created by using ASP.NET application services. From here we must create mapping files and point them to the application services. Then we can access the users credentials and profile information form the client. Ok, now let’s configure the Web site so the application services are exposed to the network.
First, we need to create a Windows Communication Foundation service file (.svc) and name it authSVCAppServices.svc, or whatever you need to name it just remember to change it when needed. To add this file, simply Right-click on the name of the Web site in the Solution Explorer and select > Add New Item > Choose WCF service.
Open the .svc file and replace the existing @ServiceHost directive with this directive, which references the System.web.ApplicationServices.AuthenticationService class:
| <%@ ServiceHost Language="C#" Service="System.Web.ApplicationServices.AuthenticationService" Debug="true" %> |
This does not implement a custom authentication service, it just calls the built-in System.Web.ApplicationServices.AuthenticationService class. Now since we are using the System.web.ApplicationServices.AuthenticationService service we do not need the custom interface and class files that were created when the .svc file was added, so you can just Right-click on them and delete them. They are located under the App_Code directory in the Solution Explorer.
I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.
Now we are ready top add another WCF service file (.svc) to the Web site. For this example name it roleSVCAppServices.svc. Replace the contents with the following directive:
| <%@ ServiceHost Language="C#" Service="System.Web.ApplicationServices.RoleService" %> |
Again located in the App_Code directory, delete the interface and class files for roleSVCAppServices.svc.
Now we are ready add another WCF service file (.svc) to the Web site. For this example name it profileSVCAppServices.svc. Replace the contents with the following directive:
| <%@ ServiceHost Language="C#" Service="System.Web.ApplicationServices.ProfileService" %> |
Again located in the App_Code directory, delete the interface and class files for profileSVCAppServices.svc.
Save and close all .svc files, and build the project to make sure that the markup, code, and configuration setting compile.
You are now ready to configure the Web Application in order to expose the application services. For you to be able to configure the applcation services you will need to open the web.config file and locate the and
| </configSections> <system.web.extensions> <scripting> <webServices> <authenticationService enabled="true" requireSSL = "false"/> <profileService enabled="true" readAccessProperties="FirstName,LastName,PhoneNumber"/> <roleService enabled="true"/> </webServices> </scripting> </system.web.extensions> <appSettings/> > |
Take into consideration in a live Web site, you should set the requireSSL atrribute = “true”/>.
Now as a child of the system.serviceModel section you will need to add a serviceHostingEnvironment element and set it to true. An example looks like this:
| </runtime> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <behaviors> … </behaviors> |
Within the same system.serviceModel group, you will need follow these steps in order to configure the applcaition services so that they can be accessed by client apps by using the SOAP protocol:
Within the system.serviceModel group element, tab down and locate authSVCAppServicesBehavior within these tabs <behaviors><serviceBehaviors><behavior>.
Once you have found that attribute change it to AppServiceBehaviors. You will need to change it for all three services. Here is example code of how the complete ssytem.serviceModel element shoud look like:
| <configuration>.. <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> <behaviors> <serviceBehaviors> <behavior name="AppServiceBehaviors"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="AppServiceBehaviors" name="System.Web.ApplicationServices.AuthenticationService"> <endpoint binding="basicHttpBinding" bindingNamespace="http://asp.net/ApplicationServices/v200" contract="System.Web.ApplicationServices.AuthenticationService"> </endpoint> </service> <service behaviorConfiguration="AppServiceBehaviors" name="System.Web.ApplicationServices.RoleService"> <endpoint binding="basicHttpBinding" bindingNamespace="http://asp.net/ApplicationServices/v200" contract="System.Web.ApplicationServices.RoleService"> </endpoint> </service> <service behaviorConfiguration="AppServiceBehaviors" name="System.Web.ApplicationServices.ProfileService"> <endpoint binding="basicHttpBinding" bindingNamespace="http://asp.net/ApplicationServices/v200" contract="System.Web.ApplicationServices.ProfileService"> </endpoint> </service> </services> </system.serviceModel> </configuration> |
We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.


Leave a Comment
#1 Air Horn
Posted By: Air Horn | 2.02.2010 at 11:37 PM
I've already bookmark this article long time ago and I'm planning to refer this to all my close friends who are working on asp.net :)
#2 aion kinah
Posted By: aion kinah | 3.01.2010 at 12:30 AM
thanks for sharing this information.
#3 coach handbag outlet
Posted By: coach handbag outlet | 3.01.2010 at 8:40 PM
Well the coach handbag outlet is one that is certainly unique and different.
#4 MBT trainers shoes
Posted By: MBT trainers shoes | 3.01.2010 at 8:41 PM
You are sure to find one for every occasion.
#5 discount christain louboutin
Posted By: discount christain louboutin | 3.01.2010 at 8:42 PM
They are known for their sleek and smart .
#6 games addicting
Posted By: games addicting | 3.07.2010 at 3:44 AM
I really liked this wonderful blog post. Please keep up the good work. Cheers!
#7 http://www.iamkaiser.com/webthesurfi-rugs-webdesign/
Posted By: http://www.iamkaiser.com/webthesurfi-rugs-webdesign/ | 3.09.2010 at 10:48 PM
Do you have a VB code for this script. My current project is not based on C#
#8 Chapel Hill Real Estate
Posted By: Chapel Hill Real Estate | 3.11.2010 at 3:58 AM
This is a really nice article. I am sure a lot of people will benefit from it. Thanks!
#9 25th Wedding Anniversary
Posted By: 25th Wedding Anniversary | 3.18.2010 at 1:33 AM
I like the way you have explained every thing. Thanks for sharing!
#10 70-291
Posted By: 70-291 | 3.18.2010 at 4:21 AM
I really liked this gorgeous blog post. Please keep them coming. Greets!!!!
#11 Towing in Redmond
Posted By: Towing in Redmond | 3.19.2010 at 2:39 AM
This is pretty refreshing article, I'm sure this will be followed by many users. :)