在开发过程中,我想出了从远程 PC 使用我的 asp.net mvc 站点的必要性。因此,我将其配置为使用 IIS Express。
首先,Windows 身份验证出现问题。我的站点应该在 Windows 域 Intranet 中工作,所以我想使用集成的 Windows 身份验证。我设法让它在 firefox 上运行 How To: Firefox and Integrated Windows Authentication来自 IIS Express Windows Authentication (bees73 的回答)。但是 IExplorer 仍然要求打印登录名/密码,即使我在本地打开它,指定我的 ip 而不是 localhost。
IE 的问题仍未解决,但顺其自然 - 如果我打印我的凭据,它就可以在本地工作。
我的问题是:当我在远程 PC 上打开我的网站时(在 Firefox(无需打印登录名/密码)和 IE(我必须打印登录名和密码)中),我的页面在没有应用的情况下呈现造型。看起来没有 css 可用。但我没有收到任何错误。
在加载页面的源代码中我确实有一行
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
但是当我尝试查看 Site.css 时,它说存在一些内部服务器错误。
我想我没有正确配置 IIS Express,这就是问题所在。如果没问题,至少我猜集成的 Windows 身份验证必须在不询问 IE 上的登录名和密码的情况下工作。
所以,我的配置:
- 元素本身 - 到 IIS Express,windows 身份验证 - 开启,匿名 - 关闭。
- netsh http 添加 urlacl url= http://myip:myport用户=域名\我的登录名
- netsh http add iplisten ipaddres=myip
- 在 applicationhost.config 中:
绑定(bind):
<site name="MySite" id="2"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="D:\..." /> </application> <bindings> <binding protocol="http" bindingInformation="*:myport:localhost" /> <binding protocol="http" bindingInformation="*:myport:myip" /> </bindings> </site>
身份验证:
<sectionGroup name="authentication"> <section name="anonymousAuthentication" overrideModeDefault="Deny" /> ... <section name="windowsAuthentication" overrideModeDefault="Allow" /> </sectionGroup>
<authentication> <anonymousAuthentication enabled="false" userName="" /> ... <windowsAuthentication enabled="true"> <providers> <add value="Negotiate" /> <add value="NTLM" /> </providers> </windowsAuthentication> </authentication>
<add name="AnonymousAuthenticationModule" lockItem="true" />
<location path="MySite"> <system.webServer> <security> <authentication> <anonymousAuthentication enabled="false" /> <windowsAuthentication enabled="true" /> </authentication> </security> </system.webServer> </location>
最佳答案
问题与 ISS Express 中的 netsh 和绑定(bind)配置有关。起初我通过我的 ip 设置它,它导致了令人困惑的错误。
在网上搜索任何内容时,我遇到了 Setting up IIS Express .都一样,但建议在 netsh 和 iis applicationhost.config 中使用 pc 名称。
所以,我添加了
netsh http add urlacl url=http://MyPCName:MyPort/ user=everyone
和
<binding protocol="http" bindingInformation="*:MyPort:MyPCName" />
还有一个奇迹!!它奏效了。
至于 IE,我必须关闭关闭“使用 Windows 授权”标志才能使其正常工作。非常感谢 Internet Explorer - Enable Integrated Windows Authentication .但是,如果在 url 中使用了 ip,IE 仍然会要求输入登录名和密码。如果使用 pc 名称,它会静默工作。
Firefox 要么要求登录名和密码(如果输入有效凭据,Firefox 就会工作)或者您应该申请 How To: Firefox and Integrated Windows Authentication (在我的问题中提到)然后它与 ip 和 pc 名称一起静默工作。
希望这对其他人有帮助。
编辑
一句话:我必须以管理员权限启动 VS2010。如果不是,我仍然会收到基于错误模拟错误的 HTTP 500 错误。因此,在 Windows 7 下没有管理员权限的 VS2010 启动的 IIS Express 似乎无法正常工作。
据我了解,线索是为 IIS_IUSRS 提供适当的权限。但在此之前,使用管理员权限启动 VS 2010 会更容易。
关于c# - 使用 iis express 时,没有在远程 pc 上应用 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13060303/