Read Build Your Own ASP.NET 3.5 Website Using C# & VB Online
Authors: Cristian Darie,Zak Ruvalcaba,Wyatt Barnett
Tags: #C♯ (Computer program language), #Active server pages, #Programming Languages, #C#, #Web Page Design, #Computers, #Web site development, #internet programming, #General, #C? (Computer program language), #Internet, #Visual BASIC, #Microsoft Visual BASIC, #Application Development, #Microsoft .NET Framework
572
Build Your Own ASP.NET 3.5 Web Site Using C# & VB
Figure 13.6. The SQL Server Setup Wizard
Leave the first option selected and hit
Next
—you’ll see the dialog shown in
Fig-
ure 13.7. Here, you
’ll need to tell the wizard which server and database you want to connect to in order to create those structures. The
Server
should be
LOCAL
\SqlEx-
press
(where
LOCAL
is the network name of your current machine), and the
Database
should be
Dorknozzle
.
Using Remote Servers
You can enter any local or remote server into the
Server
field. You might use this
tool to configure a remote server, for example, when you’re choosing to move the
application from your development machine to a remote production machine. In
that case, you’d need to select
SQL Server Authentication
and supply the username
and password provided by the server’s administrator.
Licensed to [email protected]
Security and User Authentication
573
Figure 13.7. Selecting the
Server
and
Database
Click
Next
, and you’ll be asked to confirm the data you’ve entered. Hit
Next
again, and expect a delay while the tool finishes setting up the database for you. When
it’s done, click
Finish
to close the wizard; then, when
aspnet_regsql.exe
finishes executing and a new prompt is displayed, you can close the SDK Command Prompt window.
Once your database is ready, you’ll need to modify
Web.config
to configure a new
connection string named LocalSqlServer, which points to your database. As we
mentioned earlier, this is the default connection string used by the built-in controls
and tools that need access to the membership data.
More on aspnet_regsql.exe
You can customize or automate this process by supplying parameters to the
aspnet_regsql.exe
program at the command prompt. For example, instead of running
the wizard using the steps above, you could have executed this command at the
SDK Command Prompt:
aspnet_regsql -S
LOCAL
\SqlExpress -E -A all
-d Dorknozzle
To have the tool connect using SQL Server Authentication instead of the integrated
Windows Authentication, you’d use a slightly different command:
Licensed to [email protected]
574
Build Your Own ASP.NET 3.5 Web Site Using C# & VB
aspnet_regsql -S
LOCAL
\SqlExpress -U username
-P password –A all -d Dorknozzle
Keep in mind that you can also use this tool to configure a remote database, in
which case you’d need to mention the remote server address and database instance
name instead of the local machine name and local SQL Server instance name.
If you executed the commands shown above, the output would look like that
shown in
Figure 13.8
.
Figure 13.8. Using
aspnet_regsql.exe
at the command prompt
LocalSqlServer Definition In machine.config
Should you ever want to see or modify the default definition of the LocalSqlServer connection string, you can find it in the file
\Windows\Microsoft.NET\Frame-
work\
version
\CONFIG\machine.config
.
The
machine.config
file contains default machine-wide settings, which can be
customized by each application’s
Web.config
file. Here’s the default definition of
LocalSqlServer; this snippet also shows you how to connect to a disconnected
database, such as ASPNETDB:
providerName="System.Data.SqlClient"/>
Licensed to [email protected]
Security and User Authentication
575
Modify
Web.config
so that it removes the default LocaSqlServer connection string,
then redefines it with the same connection data as DorknozzleConnectionString:
Dorknozzle\VB\09_web.config
(excerpt)
connectionString="Server=localhost\SqlExpress;
Database=Dorknozzle;Integrated Security=True"
providerName="System.Data.SqlClient"/>
connectionString="Server=localhost\SqlExpress;
Database=Dorknozzle;Integrated Security=True"
providerName="System.Data.SqlClient" />
At this point, if you experimented with the auto-generated ASPNETDB database, you
can delete the two database files,
aspnetdb.mdf
and
aspnetdb_log.ldf
, from your application’s
App_Data
folder.6
If you’re curious, open the Dorknozzle database using the tool of your choice to see
the new tables that have been created—they’re shown in
Figure 13.9
. You’ll notice that your database now has 11 new tables whose names start with aspnet.
6 It’s interesting to note that if your application isn’t using the ASPNETDB database, you’re free to simply delete its files. This is possible because, as we explained earlier, ASPNETDB is a User Instance database, the files of which are opened and read only when needed.
Licensed to [email protected]
576
Build Your Own ASP.NET 3.5 Web Site Using C# & VB
Figure 13.9. Membership tables in Dorknozzle
Using the ASP.NET Web Site Configuration Tool
After making the configuration changes we mentioned earlier, run the ASP.NET
Web Site Configuration Tool and click the
Security
tab again. If you look into the
App_Data
folder, you’ll notice that the tool didn’t create the ASPNETDB database. Instead, it’s using the Dorknozzle database. Before you start to add users and roles, it’s worth taking a look around. While you’re