Due to the stateless nature of the HTTP protocol, file and directory operations in a Web application typically do not persist after a user session has ended. However, for PowerBuilder .NET Web Forms applications, you can store user names in a database and persist data and files created by application users across Web Forms sessions. PowerBuilder .NET Web Forms can take advantage of the ASP.NET membership feature to maintain permanent user accounts and store files created or modified by application users.
The default ASP.NET membership provider is defined in the machine.config file
that is typically installed in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory.
The machine.config file assigns SQL Server
Express (.\SQLEXPRESS
)
as the default membership data source.
You can download the SQL Server 2005 Express Edition from the Microsoft download site.
You might need to uninstall SQL Native Client before installing SQL Server 2005 Express. The SQL Server Express setup produces an error if it finds an incompatible version of SQL Native Client. The SQL Server Express setup includes a compatible version of SQL Native Client that it installs if it does not find an existing version of this driver on the server computer.
You do not need to install SQL Server Express if you are using SQL Server for the permanent user database, but then you must replace the default connection string in the machine.config file or add a connection string to the web.config file for the Web Forms application. Changes to the machine.config file affect all .NET Web applications.
The connection string you add to the web.config file should have the following format for a remote database server using SQL Authentication:
<connectionStrings> <add name="MySQLServer" connectionString="Server=dbsevername; Database=aspnetdb; User Id=uid; password=pwd" providerName="System.Data.SqlClient" />
</connectionStrings>
The following connection string specifies a local SQL Server database with Windows Authentication (SSPI):
<connectionStrings>
<add name="MyDbConn" connectionString="Initial Catalog=MyDb; Data Source=MyServer; Integrated Security=SSPI;"/>
</connectionStrings>
Permanent user accounts are disabled by default. After a Web Forms application is successfully deployed, the IIS server administrator can use the following procedure to set up permanent user accounts. This procedure uses the default ASP.NET membership provider and data source assignment, although a note in the procedure describes a required change to the web.config file when you use a nondefault connection string.
To create permanent user accounts:
Run aspnet_regsql
from
a DOS command prompt window.
This starts the ASP.NET SQL Server Setup wizard.
You can enter Aspnet_regsql /?
at
the command line to obtain a list of optional parameters for SQL
Server or SQL Server Express that you can use to bypass the wizard.
If you are using a local SQL Server database, for example, you can
enter aspnet_regsql -S (local) -E -A
m
, where -S (local)
indicates
that the server is local, -E
indicates
that the connection uses Windows Authentication, and -A
m
adds the membership feature.
Use the ASP.NET SQL Server Setup wizard to create the user database.
In the wizard, you can enter .\SQLEXPRESS
as
the server name. This is the default name for the local server as
defined in the machine.config file. The wizard
should give you a success message.
In a text editor, modify the web.config file in the virtual root directory for your deployed Web Forms application (typically, C:\Inetpub\wwwroot\applicationName) to remove comment tags (<!-- and -->) from the following lines:
<!-- <roleManager enabled=”true” /> -->
...
<!-- <add name="AspNetSqlMembershipProvider"
...
passwordStrengthRegularExpression=""/> -->
These lines should now appear in the web.config file as:
<roleManager enabled=”true” />
...
<add name="AspNetSqlMembershipProvider"
...
passwordStrengthRegularExpression=""/>
If you are using a nondefault database You can change the connectionStringName parameter assignment in the uncommented lines to a value other than LocalSqlServer if you modified the connection string in the machine.config file, or if you added a connection string in the application web.config file. For example, if you named a connection string as MySqlServer, you should change the connectionStringName parameter value to MySqlServer.
Make sure that the appropriate user or user group (ASPNET for IIS 5, IIS_WPG for IIS 6, or IIS_IUSRS for IIS 7 and IIS 7.5) has write authority for the virtual root directory of your deployed Web Forms application.
The next step in this procedure creates the App_Data directory and saves database files to this directory. However, it cannot do this if the ASPNET user (Windows XP), the IIS_WPG user group (Windows 2003), or the IIS_IUSRS user group (Windows Vista and later) does not have write authority for the Web Forms virtual root directory.
If you proceed to the next step without modifying write permissions, you might get an error page indicating that you do not have write authority for this directory. The error page also explains how to grant write authority for the directory.
Open the UsersInit.aspx file for the Web Forms application in a Web browser.
The full URL for this file is typically http://ServerName/ApplicationName/UsersInit.aspx. When you open this file in a Web browser, the App_Data directory is created under the application virtual root directory and the permanent accounts database is created with the following entries:
User name |
Password |
Role |
---|---|---|
admin |
a123456& |
admin |
user |
a123456& |
user |
The UsersInit.aspx returns a success page after the above user accounts are created.
Open the Login.aspx file for the Web Forms application in a Web browser.
The full URL for this file is typically http://ServerName/ApplicationName/Login.aspx. The Login page displays.
On the Login page, enter admin
for
the User Name and a123456&
for
the Password.
The Welcome page for an administrator role has a hyperlink labeled Users that opens a page to manage users.
Click the Users hyperlink, then click the Search button in the page to manage users.
The page for managing users displays the application users in the permanent user database.
Click the Create New User hyperlink.
The page for adding users displays.
Enter a new user name, password, and e-mail. Enter the password a second time in the Confirm Password text box and click Create User.
A new user account is added to the database for the current Web Forms application.
Select the Admin Role check box if the new user should have administrative privileges, and click Finish.
When you return to the page for managing users and click the Search button again, you should see the user account you created in the list of user accounts.
Repeat steps 10-12 to create as many user accounts as necessary, then click the Logout hyperlink to log out from the user management role.