This may be a little specific, but there are most surely some solutions for others in this mix. Here is what I had to do to port my asp.net website from a Development environment (MS VS 2010, SQLEXPRESS) to IIS 7.
What this will explain, is how to set up two web application under one website (Website1, and Website2). Website1 will use aspnetdb.mdf (created by visual studio) and Website2 will use website2 database which was manually created in MS SQL Server 2008. We will be porting the aspnetdb.mdf to sql server 2008 as well for ease of manipulation.
Website1 will also have permissions to create files and directories on website2.
Section 1 IIS Setup
****Step 1:****
create a new folder in wwwroot to hold both applications (We called it websites)
Copy paste "WebSites" folders for website2 and website1.
Step 2:
App pool for website1
If not already created, create the Application pool and configure it to use .NET framework 4.0, Integrated pipeline mode, we called it asp4.
App pool for website2
Currently uses App pool for website1
Step 3:
Add website1
In IIS MANAGER, add new website. Point its physical directory to website1 that we just copied into the new folder on the root (Section 1, Step 1).
Select the application pool for website1, See Section 1, step 2.
We set the site name the same as the physical directory (website1).
Verify other requirements, Section 2 website1 DB Setup and IIS folder permissions.
Add website2
In IIS Manager, right click the new website application we just created, select "Add Virtual Directory".
Set the physical path to the website2 folder that we copied to our new folder on the wwwroot holding both applications, See Section 1, step 1.
Convert to application and select the application pool for website1, See Section 1, step 2.
We set the alias to the same as the physical path folder, website1.
Currently, there are no connection requirements to pass through.
Verify other requirements Section 3 - website2 Database setup for website2
Section 2 website1 DB Setup and IIS folder permissions
Step 1 aspnetdb.mdf adjustments:
Note: From now on will probably just use most recent aspnetdb.bak file.
Attach aspnetdb.mdf into ms sql server by rightclicking database's and attaching DB.
Step 2 - IIS User logon
If user is not set up - Section 4, Step 1 Create a DB Logon for the IIS USer
if permissions not setup - Section 4, Step 2 Setting Permissions for the IIS USER on the db
Code Adjustments / Verifications
need to remove user instance variable (;User Instance=true) auto generated in connection string by MS VS in web.config.
- <remove name="ApplicationServices"/>
- Not 100% neccessary but this will make it more scalable accross platforms
- In the web.config, make sure we are using the database we attached / restored on MS SQL Server.
- "data source=.\SQLEXPRESS;Integrated Security=SSPI;initial catalog=aspnetdb" (because we renamed it aspnetdb)
Section 3 - website2 Database setup for website2
Make sure DB is restored on MS SQL SERVER
Database requirements
Step 1
If user is not set up - Section 4, Step 1 Create a DB Logon for the IIS USer
Step 2
if permissions not setup - Section 4, Step 2 Setting Permissions for the IIS USER on the db
Step 3 Folder permissions (after child site website2 is added)
Set folder permissions : Since website1 writes files and creates folders in website2, (its set up to be always looking in the parent folder for website2 folder) we need to give server IIS_IUSRS , ours is (IIS_IUSRS(MIKE71\IIS_IUSRS) permissions.
From within IIS, rightclick the nested application website2 and select edit permissions. Ensure that modify and write priveledges are checked off for IIS_IUSRS.
Section 4 - Adding IIS user to databse and giving permissions
Step 0 Attaching and restoring the Databases
- If the database is not already attached to MS SQL Server, we need to attach the .mdf file.
- We can restore the database by rightclicking Databases, restoring to our Attached Database, and restore from supplied .Bak file.
- If having troubles restoring because of database definitions (creating a clean one from scratch) try:
RESTORE DATABASE trimweb
FROM DISK = 'C:\trimweb.bak'
WITH REPLACE
Step 1 Create a DB Logon for the IIS USER
Why? Need create and allow IIS APPOOL\asp4 user to have permissions to databse, set as data reader (the application pool created in Section one, Step 2)
How: In the security section in MS SQL SERVER, need to right click users and add IIS APPPOOL\asp4 (IIS APPPOOL\apppoolname, created in Section one, Step 2).
Add IIS 7 AppPool Identities as SQL Server Logons
Step 2 Setting Permissions for the IIS USER on the db
Right click on the database name, (website2 db) and click properties. In permissions section add your APPPOOL user that you just created in Section 4, Step 1, be sure to give him Execute and Select permissions.
Note: Website1 needs Execute, Select, Delete, Insert permissions as well. Website2 is also using this app pool which it shouldnt be because we dont not need to alow the user to have that kind of functionality from within the trimdynamics application. We could seperate the app pools so that our trim dynamics IIS USRS is only getting Execute and Select permissions.