Learn How to Enable Configuration Settings in ASP.NET 3.5 C#.

Category: XML and Web Services

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:

Then add the roleManager element to configure the roles services:

While still in the system.web section, configure the profile serivce through the profile section and its properties element like this example:

 
 
 
 
 

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:

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:

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:

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 element and add a new element. You will also need to add a element to the system.extesnions element to enable authenication, profile, and role services through the webServices section. This examnple shows how this section should look:


 
 
 
 
 
 
 

 

 

>

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:


 
 
 

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 .

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:

..















name="System.Web.ApplicationServices.RoleService">



name="System.Web.ApplicationServices.ProfileService">





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.



Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!