开发者

ASP.NET MVC 2, Windows XP, and IIS 5.1

I'm getting headaches from trying to host MVC 2 on XP's IIS! (This is on VS 2008, but probably applies to VS 2010 as well.)

After much struggling I eventually found a way to display my MVC 2 site from IIS 5.1, 开发者_运维技巧but the problem is that there is no styling! Any ideas on how I should fix this?

The problem is probably the path location. Following the suggestions from the link above, if I change the relative path of my CSS link from <link href="../../Content/Site.css" rel="stylesheet" type="text/css" /> to <link href="%3C%=Url.Content%28" ~="" content="" site.css="" )="" %>="" rel="stylesheet" type="text/css" /> then it does not do any conversions. When I change it to <link href="<%=Url.Content(" ~="" content="" site.css="" )="" %>="" rel="stylesheet" type="text/css" /> then I get the error "Newline in constant."

EDIT: The normal <link href="<%= Url.Content("~/Content/Site.css")%>" rel="stylesheet" type="text/css" /> translates to <link href="/Mvc2.VS2008/Content/Site.css" rel="stylesheet" type="text/css" /> (where Mvc2.VS2008 is my website root), but Content/Site.css is not found when hosted this way.


I'm not exactly sure what the problem was, but the value returned by Url.Content() was not recognized by the IIS Server (you could not retrieve it from the browser). In fact, I am not supposed to need it for simple links anyway.

Steps to fix:

  1. Completely reinstall IIS 5.1 (uninstall, reboot, delete C:\Inetpub folder, install).
  2. Register .NET for IIS (first v2 then v4): (Error message = "Failed to access IIS metabase")
    • In command prompt, go to the appropriate folder (e.g. cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727)
    • aspnet_regiis -i
    • iisreset
      • If this step fails with the error "The service did not respond to the start or control request in a timely fashion. (2147943453, 8007041d)", silently curse from the frustration, and restart the site manually through the IIS console (Start -> Programs -> Administrative Tools -> Internet Information Services). If you are (rightfully) paranoid, restart your PC.
  3. Add READ access to Everyone
    • Download MetaAcl
    • Open command prompt
    • Metaacl.vbs "IIS://localhost/W3SVC"
      • View current access (Everyone only has E)
    • Metaacl.vbs "IIS://localhost/W3SVC" Everyone R
      • THIS FIXED IT
  4. Add IIS Virtual Directory
    • You know, in the IIS console for the "Default Web Site."
  5. Reminders on publishing: (you should know this already)
    • Windows authentication (<authentication mode="Windows" /> in web.config) requires you to enable Integrated Windows Authentication in the IIS Directory Security.
    • It helps to disable anonymous access. (Add <authorization><deny users="?"/></authorization> in web.config, or uncheck "anonymous access" in the IIS Directory Security)
  6. Configure IIS virtual folder
    • IIS Configuration Mappings (Right-click the virtual folder -> Properties -> Virtual Directory Tab -> Configuration -> Mappings Tab)
    • Add extension ".*", exec path = (copy from the ".aspx" extension)
    • Uncheck "check that the file exists"
    • Click OK (this goes without saying)
  7. Load your website in your favourite browser.

Now everything should be just peachy (it worked on my PC). There should no longer be any need for Url.Content(), and styling should just work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜