Journal – Setting up a “Townhall” website (My thanks to Jeremy H and yousaid for getting me here)
My objective is to create a “Townhall” Website for the citizens of the City of Cushing, OK. I intend to begin by using the “classifieds” website starter kit from Microsoft (but instead of “things to sell”, each ad will be a mini-webpage for local businesses). Later I hope to add the timetracker starter kit (to allow local service clubs to track donations to charity), and a PHPBB-based forum as an “online townhall”, for threads such as, “What questions do you have for the Mayor?”. See www.cushingshops.com
We shall attempt to present a very step-by-step (“cookbook”) approach, with a lot of “cut-and-paste”.
Email me at tcscushing@aol.com for code samples (only useful for absolute beginners).
Downloads from here: http://msdn.microsoft.com/vstudio/express/default.aspx
Microsoft MSDN 2005 Express Edition, Visual Web Developer 2005 Express Edition, with Reporting Add-ins, Visual Basic, Visual C#, Visual C++, Visual J#, SQL Server Express, MS SQL Server 2005, Server Mgmt Studio Express SP2, Native Client, Setup Support Files (English), VSS Writer, MSXML 6.0 Parser
Website Starter Kits (downloaded, installed, and seem to work)
http://msdn.microsoft.com/vstudio/express/vwd/starterkit/default.aspx
MS .Net Framework 1.1/2.0/SDK, MS Platform SDK, User-mode Driver Feature Pack 1.0
Open Office, J2SE Java Runtime
Download latest Classifieds Starter Kit from: http://www.asp.net/downloads/starterkits/
This gave me a 647 kb file named class.vsi, Executing this gave me a template in VWD2005Exp (Visual Web Designer), Starting new website gave me a working website folder in VWD2005Exp, “classifieds1”, Save-all, exit, re-open classifieds website, highlight default.aspx, ctl-f5 to start execution, Click on “register”, enter admin-member info, exit/save-all, re-open classifieds website, Following instructions near the bottom of the welcome.html, used the asp.net Web Site, Administration Tool to set the role of the only user in the database, to both “administrator” and “guest” (but I think only “administrators” was necessary)
Started the application (locally, within VWD2005Exp using ctrl-f5 and IE7), added a normal user, tested logging on to both existing users. The admin could see the admin-function tab, guest could not. I was able to create and “ad” with pictures for the guest member.
Setting up 1and1 hosting specs/prep
This is a $10 a month MS Hosting site, supporting asp.net 2.0, deleted their original files from the root directory.
I set up FTP permissions using the 1and1 control panel, and created a “main” subdirectory (and a couple other test directories). I replaced the “default.asp” in the root directory with a “redirector” script, and placed test default.aspx “parking” pages in each subdirectory, to test my redirector. The following shows 1and1's example of an asp script redirector:
http://faq.oneandone.co.uk/script_cookbook__databases/asp_net/asp_net_2_0/1.html
I then set the “main” subdirectory (folder) to all possible permissions, and also indicated that it was an “application” thru the 1and1 control panel. This is the application name you will need for the setup of the membership in web.config file. Also from “webfiles” of the 1and1 control panel, set “write” permissions for the “upload” subfolder, and for the “site-config.xml” file within the App_Data subfolder.
Note: 1and1 will not allow you remote access to the SQL Database, so you can't run aspnet_regsql.exe directly against your database.
I set up a blank database thru the 1and1 control panel, went into the database admin, and noted the info needed to set my web.config connection strings.
I moved all files from the “classifieds” folder locally to the “main” folder at my site. I removed the copies of my local databases from the “App_Data” folder (ASPNETDB.MDF, and CLASSIFIEDSDB.mdf, and .ldf and .log files). I modified the web.config connection string, and other source files as noted.
On my local PC, I set up a .bat file to run aspnet_regsql.exe as a commandline process to create a .sql script which would create the “aspnet” portion of my database. On my PC, it was in:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe
(Set up a .txt file in the same folder as the aspnet_regsql.exe, change the extension to .bat, and edit it to look like this:)
aspnet_regsql.exe -S [mssqlxx.1and1.com] -U [dboyyyyyyyyy] -P [zzzzzzzz] -A all
-d [dbyyyyyyyyy] -sqlexportonly [aspnet_add.sql]
I guess you can make out the options here
-S = your 1and1 sql server (xx) instance name
-d = Database/DB Owner name (yyyyyyyyy and password zzzzzzzz)
-sqlexportonly = the name of the file you need, in this case “aspnet_add.sql” is created.
(I think the -U [dboyyyyyyyyy] -P [zzzzzzzz] switches were not necessary)
I used the 1and1 MS-SQL admin, mylittleadmin tool, tools, Query Analyser tool to run this script, specifying where on my local PC the script was. Then tables, stored procedures, and views were created, for the “aspnet functions” portion of the DB out on 1and1.
Do I care about SQL CACHE DEPENDENCY OPTIONS? (Jeremy replies:) - Well I have yet to really need this on any start kit project that I have worked on but you can read more if you want at http://msdn2.microsoft.com/en-us/library/ms229862(vs.80).aspx - Also this may help you http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=1130
Using the same 1and1 MS-SQL admin tool, I ran the scripts from the App_Data folder (open each of these with notepad, classifieds-add.sql, and classifieds-categories.sql, copy, paste, and run each from the text window of the query analyzer). This created the Classifieds database, with its tables, views, and stored procedures, as well as setting up the initial categories. Now both Databases that had been on my local PC were combined into 1 DB out on my 1and1. From the MS SQL Admin tool, you should be able to see aspnet and the classified tables, noting that there are 7 entries under the categories, and 2 entries under the roles. (Do NOT run the "classifieds-remove.sql" script, as it will remove your previous work).
We used internet explorer and went to cushingshops.com, and created the first member. Then we used “Users.aspx” (contributed by JeremyH, located in the “Main” subdirectory, and later moved to the “admin” subdirectory) to set the role of the first member to “administrators”.
We then added a “guests” member, and used this logon to create an “ad”, complete with pictures.
Other notes and techniques: (Mostly from JeremyH)
Well the "aspnet_UsersInRoles_GetRolesForUser" procedure I deleted when I was checking with the connection string and the web.config so I could be sure that I had a hard error to work from. To put it back I just cut the text from the sql file we made to setup the aspnet function database and copied into the query editor in sql admin on 1and1 and that added it.
<snip>
CREATE PROCEDURE dbo.aspnet_UsersInRoles_GetRolesForUser
@ApplicationName nvarchar(256),
@UserName nvarchar(256)
AS
BEGIN
DECLARE @ApplicationId uniqueidentifier
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM aspnet_Applications
WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN(1)
DECLARE @UserId uniqueidentifier
SELECT @UserId = NULL
SELECT @UserId = UserId
FROM dbo.aspnet_Users
WHERE LoweredUserName = LOWER(@UserName) AND ApplicationId = @ApplicationId
IF (@UserId IS NULL)
RETURN(1)
SELECT r.RoleName
FROM dbo.aspnet_Roles r, dbo.aspnet_UsersInRoles ur
WHERE r.RoleId = ur.RoleId AND r.ApplicationId = @ApplicationId
AND ur.UserId = @UserId
ORDER BY r.RoleName
RETURN (0)
END
</snip>
> There are two databases, the aspnet and the classifieds. On the local machine, the aspnet db is created during the first run by Visual Web Developer 2005 Express, it is created when you run the project (F5) or when you use the ASP.NET Configuration tool.
> Running aspnet_regsql.exe on the local machine, when this is run in GUI mode, it attempts to hook to the DB that is specified. But when run as a commandline, it just cranks out a sql script, and this script seems to be the same, whether or not it refers to an actual DB. The simplest logic is to create a hosted database then use an install script for the main application database, then add the aspnetdb with the install script created by the command line tool aspnet_regsql.
> The difference between the aspnet DB which has "DBO." as its owner and the classifieds DB which has "DBOyyyyyyyyy" as its owner. Where do we differentiate? Well the DBOyyyyyyyyy is your named SQL Server login account (User) to the 1and1 sql server that gives you full rights to your database but SQL Server has a "dbo." fixed server role which means the owner of that database. So from a web.config or connection string point of view you have to use the username (DBOnumbers) and password pair (for the classifieds db portion) but within sql server you can use the fixed role (that is, only “DBO.”, for the aspnet portion of the 1and1 database).
> How do I "backup" a local DB.MDF file to make a .BAK file? You need to have SQL Server Management Studio or the express version to do that (first move a copy of the .mdf and .ldf and log to a directory close to the root of your local PC's hard drive root directory) then you right click on the database, then “tasks” and “backup”. Then you would need the isp/host to allow you to restore the database onto their server (which 1and1 seems to allow), You can end up with problem doing this if username and permission and version are not the same. I think the best route is install scripts as this give you much more control.
> In the documentation for 1and1, it says that the first time you "publish" (move the source to the public server's folder), it is a good idea to enable frontpage extensions and use Visual Web Designer Express to copy the stuff to the server. This somehow registers the applications or something. Was this necessary, or could I have only used FTP exclusively? (Jeremy replies:) Yes ftp is fine. The Copy web site in VWD is slow for some reason and the ftp copy does not need frontpage extensions, I am not 100% sure why you need frontpage extensions but I think its todo with Webdav, http transfer. I have read that Microsoft is not releasing any new version of the extensions.
Code samples:
WEB.CONFIG: Note changes must be made to xx, yyyyyyyyy, and zzzzzzzz below. Get this information from the 1and1 control panel, MS-SQL, admin for your database.
Also when you have finished setting up and testing the website you should change <compilation debug="true"/> to <compilation debug="false"/> this will speed up the site and allow caching of the pages.
<?xml version="1.0"?>
<configuration>
<location path="Admin">
<system.web>
<authorization>
<allow roles="Administrators"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
<location path="PostAd.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="EditPhotos.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="MyAds.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<location path="MyProfile.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<system.web>
<customErrors mode="Off"/>
<authentication mode="Forms"/>
<!--<identity impersonate="true"/>-->
<compilation debug="true"/>
<pages styleSheetTheme="Red"/>
<membership defaultProvider="CustomizedMembershipProvider" >
<providers>
<add name="CustomizedMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="/main"
requiresUniqueEmail="true"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7"
minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10"
passwordStrengthRegularExpression=""/>
</providers>
</membership>
<profile enabled="true">
<properties>
<add name="FirstName" type="System.String"/>
<add name="LastName" type="System.String"/>
<add name="MemberId" defaultValue="0" type="System.Int32"/>
<group name="Core"/>
</properties>
</profile>
<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
<providers>
<add name="CustomizedRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="LocalSqlServer" />
</providers>
</roleManager>
<siteMap defaultProvider="RoleEnabled_AspNetXmlSiteMapProvider" enabled="true">
<providers>
<clear/>
<add name="RoleEnabled_AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
</providers>
</siteMap>
</system.web>
<connectionStrings>
<add name="classifiedsConnection" connectionString="server=mssqlxx.1and1.com;
initial catalog=dbyyyyyyyyy; uid=dboyyyyyyyyy; Pwd=zzzzzzzz"/>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="server=mssqlxx.1and1.com;
initial catalog=dbyyyyyyyyy; uid=dboyyyyyyyyy; Pwd=zzzzzzzz"/>
</connectionStrings>
<!--<system.net>
<mailSettings>
<smtp>
<network host="yourSMTPhostname" port="25" defaultCredentials="true" userName="enterUserNameHereIfRequired" password="enterPasswordIfRequired"/>
</smtp>
</mailSettings>
</system.net>-->
</configuration>
USERS.ASPX: (used to change the role of an existing member to “administrators”) (contributed by jeremyh)
This page is put into the “/main” folder (modify the redirector to call it one time) to change the role of the first member. Then delete the reference to it in the redirector script in the root 1and1 directory. Also, move the users.aspx and .cs to the admin folder, and modify the /admin/default.aspx to call it.
(SECURITY WARNING! THIS PAGE MUST BE MOVED FROM /MAIN AFTER FIRST USE!)
Download code from: http://home.mchsi.com/~j.roal/Users.zip
See notes from the author: http://forums.asp.net/t/1028620.aspx jroal http://www.jimroal.com/
>end of document