Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

asp.net mvc 4 - How can I host multiple websites in IIS 7 and use the same MVC application for all them?

How can I host multiple websites in IIS 7 and use the same MVC application for all them such that each website:

  1. Has it's own root directory so user's can upload their own files (html, css, javascript) without seeing other websites'content

  2. Uses the same MVC application - so updates to the application affect all sites

  3. Users cannot affect the MVC application in any way (preferably it will be hidden from them)

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. Create a directory where you deploy the MVC files, named "AppFoo". Note that the configuration file web.config will be shared between all of the sites, you'll have to load per-site configuration at on-demand runtime by looking at the Host HTTP header or other binding information.
  2. Create each website in IIS and get it to use the the application directory you created. Ideally each website runs under its own application pool with its own user-account, all of the user-accounts will have access to AppFoo directory.
  3. Create a new directory somewhere, e.g. under C:Inetpubsites named WebsiteA, WebsiteB, etc. Each folder re-sets the NTFS permission ACLs that only allows each website's application pool user access. Inside these create folders called "Content", "Views" and "Logs"
  4. For each website in IIS (I assume you're using the root) set up a Virtual Directory called "Content" and "Views" (which is how I assume you have set-up your MVC applications), map these to subdirectories of the folders you created in Step 3.
  5. For each website, go to the Logging page and set the log-path to the Logs directory you created for the site in step 3.

Note that this plan is based on the assumption that MVC evaluates IIS virtual directories in its VirtualPathProvider. If not then you'll have to roll your own VirtualPathProvider to load per-website content, again, on a per-hostname basis.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...