- From the Build menu choose Publish Web Site:
- You can either accept the default location or change it to something else:
Make note of the location chosen as you will need it shortly.
- Now let’s configure the website in IIS 7. Launch IIS manager from Control Panel | Administrative Tools | Internet Information Services (IIS) Manager:
Hint: IIS Manager is the configuration tool for IIS and you’ll be jumping into it often. You can use the Run dialog for faster access via the Windows + R then typing “inetmgr”:
- Expand the tree control on the left, right-click on Default Web Site then right click and choose Add Application:
- Type in an Alias name that will be used as the website name when browsing, Select the ASP.NET v4.0 Application pool and choose the same Physical path where you just published the website to previously. You should click the Test Settings button to verify that Authentication and Authorization are configured correctly:
- If you received the above Authorization error it means that IIS does not have permission to access the folder where you published the website to. If this occurs, click Close then OK to complete the creation of the application. Back in the tree view control right-click on Edit Permissions to grant the IIS web server permission to the publish folder:
- On the Security tab choose Edit, then Add, then Advanced, and finally Find Now:
- From the list of users and groups use Control + click to select the follow three:
- IIS_IUSRS
- IUSR
- NETWORK SERVICE
Now you can click OK through until the dialogs are dismissed, right-click on the Website in the tree control again and choose Edit Application where you can Test Settings again.
- IIS_IUSRS
- When testing from within Visual Studio we are running under the permissions of ourselves – the account we signed into Windows with. When browsing against IIS, it is IIS that is connecting to the database. Since the IIS web server will be acting as a proxy for the user when accessing the database, you must grant the IIS user permission to the database. Using SQL Server Management Studio, execute the following T-SQL statements:
CREATE LOGIN [IIS APPPOOL\ASP.NET v4.0] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english] GO CREATE USER [AdventureWorksUser] FOR LOGIN [IIS APPPOOL\ASP.NET v4.0] GO EXEC sp_addrolemember 'db_datareader', 'AdventureWorksUser' GO
- Finally right-click on the website again, choose Browse:
- Sit back and enjoy the fruits of your hard labor:
Seeking a pragmatic approach to software development blending proven designs with real-world constraints.
Monday, December 20, 2010
How To Build a 2-Tier ASP.NET 4.0 Web Site–Part 3
Saturday, December 18, 2010
TD Bank website team is sloppy
Hmmm…Saturday before Christmas here in the U.S. of A., major banking site, error page like this:
I’ve been developing in ASP.NET since 2002 so I think I can safely say that somebody screwed up and they’ve got some sloppy practices in place!
Looks like ‘Banknorthct’ is a valid #bankid# token in case you’re trying to discover information about their site. Also, they like to use D:\websites to store their site files in so hackers shouldn’t have to go hunting for that configuration detail. Finally, they’re running .NET 2.0 which means it’s a lot easier for folks to attack because they can immediately try all known exploits.
Do I seem too harsh? Well, two simple steps would’ve prevented this:
- Turn ‘RemoteOnly’ back on in your web.config – someone explicitly changed it from the default value.
- Code a custom error page possibly with a redirect so the customer doesn’t see your dirty underwear!!
Tell me again how much banks got for a bailout in ‘09 and ‘08 and how much profit are they raking in now?
Wednesday, December 15, 2010
Install IIS 7.5 on Windows 7
Here are the quick steps for installing IIS 7.5 on Windows 7 Professional/Enterprise/Ultimate. While Microsoft’s TechNet does have an entry it’s not the most informative or person-friendly (person being different than a techie geek). This post is a companion to the How To series on building a 2-tier ASP.NET 4.0 web site (part 1, part 2, part 3).
- Navigate to Control Panel | Programs | Turn Windows features on or off:
- Check the box next to Internet Information Services and then expand the sub-tree by clicking the (+) plus sign next to it:
- Continue expanding the sub-tree until you open Application Development Features then check the box for ASP.NET:
- Further down, expand Security then enable Basic Authentication and Windows Authentication:
Clicking OK to close the dialog out will cause the computer to install and pre-configure IIS, taking several minutes to complete. - After IIS is installed you’ll find a new set of folders has been created:
C:\inetpub\wwwroot is the default “root” folder for IIS (a.k.a. world wide web server) so this path is the default location to place websites. The key fact here is that if you publish into this folder you won’t have to worry about folder (NTFS) permissions. Publishing to the default personal user location that Visual Studio selects – within your “My Documents” folder means you need to take an extra step of granting IIS permission to access those folders in your documents area. This screenshot from IIS Manager shows the default web site along with the path matching the path shown above: - Next we’ll configure Application Pools that will host and execute the ASP.NET applications. Launch IIS Manager from Control Panel | Administrative Tools | Internet Information Services (IIS) Manager:
Hint: IIS Manager is the configuration tool for IIS and you’ll be jumping into it often. You can use the Run dialog for faster access via the Windows + R then typing “inetmgr”: - When you select the Application Pools entry in the tree control you should see the following:
However, a standard configuration of IIS 7.x on Windows Server 2008 R2 looks like this:
Notice that the server installation contains two additional application pools configured for ASP.NET v4.0. - Let’s configure our personal machine (desktop/laptop) in the same manner to enable more realistic local testing. Right-click on the Application Pools entry in the tree control and choose Add Application Pool:
After adding the integrated mode, repeat the steps to add a classic mode pipeline: - Since IIS was not installed and ASP.NET was already present in Windows 7, we must manually register the “handler” for ASP.NET pages and content so IIS can correctly map web requests. To do so open a command prompt running as Administrator – necessary because this type of registration requires elevated permissions. To open a command prompt as Administrator click the Start button, type in “command” and wait a moment until it shows the Command Prompt under the Programs section then right-click and select Run as administrator as shown here:
- With the command prompt open execute two commands by typing in each of the following and pressing Enter after each command:
cd %windir%\Microsoft.NET\Framework\v4.0.*
aspnet_regiis.exe –iNote that the last four digits of the build number (30319 shown above) are less important. You may have a different version depending on the service pack level and patches installed in your computer.
That’s it – you’ve installed IIS, enabled common security features and created application pools designed to host ASP.NET 4.0 websites.
Monday, December 13, 2010
How To Build a 2-Tier ASP.NET 4.0 Web Site–Part 2
- Add a new page named Result.aspx as described previously in step 3:
- Switch the content area to “split” view using the tabs at the bottom, located the GridView control in the toolbox and drag it onto the design surface:
- To configure the data source click on the small arrowhead in the upper right section of the grid view control to expose the configuration pane as shown here:
- Click the drop-down control next to “Choose Data Source:” above and select “<New data source…>” which will launch the Data Source Configuration Wizard:
As shown above, select the SQL Database icon and input a meaningful name (or accept the default).
- Clicking “OK” will bring up the next dialog to choose a database connection where you’ll select the New Connection button:
- In the Add Connection dialog specify the name of the SQL server – this can be (local) if SQL (or SQL Express) is installed on the same machine you’re working on or another machine:
For (local) machines you should be able to the leave the Log on to the server default as Use Windows Authentication. For remote machines you might have to switch to Use SQL Server Authentication and supply a user name / password combination – unless your machine is part of a Windows domain as is usually the case in corporate environments. The selected database name should be AdventureWorksDW2008 or AdventureWorksDW2008R2 depending on which version you installed.
- Press the Test Connection button to verify that these settings work. If the test fails seek help or otherwise resolve the problem before continuing.
- Save the Connection string and continue:
- Choose the DimCustomer table for the Select statement:
- Choose FirstName, MiddleName, LastName, BirthDate, Gender, and Phone for columns and click the WHERE… button:
- Select the CustomerKey as the Column name to filter on, specify Form as the source (i.e. use Request.Form collection value) then type the name previously used as the ID for the Textbox control in step 5:
- After clicking the Add button you’ll see the WHERE clause that has been constructed and you can click Test Query to verify that the SELECT statement executes properly as expected:
- After clicking the Add button you’ll see the WHERE clause that has been constructed and you can click Test Query to verify that the SELECT statement executes properly as expected:
- Save your work then move back to Default.aspx to wire the Submit button to post back to the new Result.aspx page:
Clicking the ellipsis next to the PostBackUrl brings up a list of pages within the project where you can select Result.aspx:
- Right-click on Default.aspx in Solution Explorer and set it as the start page:
- Finally, hit “F5” to test the site:
Note the following:
- The port number shown above (:1483) will be different – Visual Studio generates a random port number for each web project.
- Visual Studio contains (hosts) a built-in “mini” web server functionally identical to the full-blown web server IIS (Internet Information Server). However, this server is restricted to a minimum number of browser connections and can only be accessed via a web browser on the same machine Visual Studio is on.
At this point we’ve got a working 2-tier ASP.NET 4.0 web site that’s prompting for a customer, querying a SQL database and displaying the results in a grid (tabular) format. Next we’ll setup IIS 7.5 on Windows 7 then deploy the site out to a commercial web server.
Thursday, December 9, 2010
How To Build a 2-Tier ASP.NET 4.0 Web Site–Part 1
Environment:
- Windows 7 Business/Enterprise/Ultimate (Home & Home Premium should work)
- Visual Studio 2010 Professional/Premium/Ultimate
- IIS 7.5
- Launch Visual Studio 2010 then create a new website project (File | New | Web Site):
- Ensure that Visual C# is chosen under Installed Templates on the left, that .NET Framework 4 is chosen in the drop-down and then pick ASP.NET Empty Web Site:
Hint: Note the path of the Web location as you will need it later on when deploying to IIS.
- Add a new Web Form page by right-clicking on the project entry in Solution Explorer and choosing Add New Item. If the Solution Explorer is not visible, use View | Solution Explorer or Ctrl + W then S to display it:
Notice that the 2nd entry in the tree view on the left is highlighted, the pop-up context menu will be different depending on which item you right-click on. The 1st entry is called the “solution” which is a container of sorts that can contain one or more projects.
As before, ensure that Visual C# is chosen under Installed Templates and pick Web Form:
Leave the defaults at the bottom of the dialog as shown above.
- Switch to “split” view in the designer panel to more easily see the effect of your actions. Open the toolbox to the “Standard” section (if the Toolbox is not visible, use View | Toolbox or Ctrl + W then X to display it) then drag ‘n drop a label control onto the designer portion of the form as shown here:
Notice the lower “Design” pane show the visual design surface while the upper “Source” view shows the underlying code created in response to dragging and dropping the control. Update the label text as shown here:
- Repeat the same process to add a Textbox following the label:
Resulting in the following:
Note the default ID of the control: TextBox1. Change it to something more meaningful such as txtCustomerId.
- Repeat the process a 3rd time adding a Button control:
Change the text label of the button to Submit.
Monday, November 8, 2010
MacBook Pro reflections
It’s been almost two months since I switch my work machine to a MacBook Pro. I’ve been asked a few times what I thought after having used it for a while. Honestly, I’ve got mixed feelings. First the pros:
- Ergonomics – the hardware is very nice. The size and feel of the aluminum uni-body is great. There’s lots of little touches like the auto-dimming and the track pad. I’ve even found myself trying to use two- and three-finger gestures on a PC touch pad when I happen to use one.
- The general thoughtfulness that goes into features like the widgets, Finder, and overall ease of use
However, there are still things that I don’t like or agree with:
- Insistence on a single-button mouse. Even after using a Magic Mouse for a while I still find that my two button, scroll wheel PC mouse is much more useful – perhaps it comes from almost two decades of using a PC-style mouse.
- Lack of consistency in keyboard shortcuts. Generally the basic keys like Command+A, Command+C work okay but apps tend to be different enough that it’s annoying. Sometimes its Control+ and other times its Command+.
- Price.
I just priced out a full Dell XPS 17 with upgraded bells ‘n whistles and still came in at $2K while the MacBook Pro is $3K loaded. That’s a full 50% premium above a high-end PC! I’m also finding that it is…well, a machine – a computer. I can be productive and useful with either one but I just don’t get the rabid fan boy, bash a PC whenever possible, pry-it-out-of-my-cold-dead-fingers feeling. Now, I’m not a graphics designer – just a corporate business user so I have Office 201x on both the Mac and Windows 7 as well as the same browsers, chat programs, and pretty similar utilities.
Saturday, October 16, 2010
MacPorts - a slick system for easily installing OSS
Want to install Tomcat? It's as simple as...
$ port list tomcat*
tomcat-native @1.1.20 java/tomcat-native
tomcat5 @5.5.25 java/tomcat5
tomcat6 @6.0.29 java/tomcat6
sudo port install tomcat6
Voila. There's 7,434 ports available at this time.