3

在开发过程中,我想出了在远程 PC 上使用我的 asp.net mvc 站点的必要性。因此,我将其配置为使用 IIS Express。

起初,Windows 身份验证出现了一个问题。我的网站应该在 windows 域内联网中工作,所以我想使用集成的 windows 身份验证。我设法通过How To: Firefox and Integrated Windows Authentication from IIS Express Windows Authentication(bees73 的回答)让它在 Firefox 上运行。但是 IExplorer 仍然要求打印登录名/密码,即使我在本地打开它,指定我的 ip 而不是 localhost。

IE 的问题仍未解决,但顺其自然 - 如果我打印我的凭据,它确实可以在本地工作。

我的问题是:当我在远程 PC 上打开我的网站时(在 Firefox(无需打印登录名/密码)和 IE(我必须打印 login'n'password)中)我的页面在没有应用样式的情况下呈现。看起来没有可用的css。但我没有收到任何错误。

在加载页面的源代码中,我确实有行

<link href="/Content/Site.css" rel="stylesheet" type="text/css" />

但是当我尝试查看 Site.css 时,它说,有一些内部服务器错误。

我想我没有正确配置 IIS Express,这就是问题所在。如果没问题,至少我猜集成的 Windows 身份验证必须在不询问 IE 上的登录名和密码的情况下工作。

所以,我的配置:

  1. 项目本身 - 到 IIS Express,Windows 身份验证 - 开启,匿名 - 关闭。
  2. netsh http 添加 urlacl url= http://myip:myport用户=域名\mylogin
  3. netsh http 添加 iplisten ipaddres=myip
  4. applicationhost.config

绑定:

<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>
4

3 回答 3

4

问题与 ISS Express 中的 netsh 和绑定配置有关。起初我通过我的 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 - 启用集成 Windows 身份验证。但是,如果 url 中使用了 ip,IE 仍然要求输入登录名和密码。如果使用 pc 名称,它会静默工作。

Firefox 要么要求输入登录名和密码(如果输入有效凭据就可以工作),或者你应该应用如何:Firefox 和集成 Windows 身份验证(在我的问题中提到),然后它可以使用 ip 和 pc 名称静默工作。

希望这对其他人有帮助。

编辑

一句话:我必须以管理员权限启动 VS2010。如果不是,我仍然会收到基于错误模拟错误的 HTTP 500 错误。因此,在 Windows 7 下,由 VS2010 启动的没有管理员权限的 IIS Express 似乎无法正常工作。

据我了解,线索是给 IIS_IUSRS 适当的权限。但在此之前,以管理员权限启动 VS 2010 会更容易。

于 2012-10-25T06:09:10.220 回答
2

可能是解析Css所在的根路径出错。您可以尝试使用 Url 助手来解决此问题。

<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/Site.css")"  media="screen" />

在 Asp.net 开发服务器(在 Visual Studio 环境中)<link href="/Content/Site.css" rel="stylesheet" type="text/css" />可以正常工作。但是在 IIS 中托管时,无法使用相对路径解析根路径。在 URL 助手的帮助下,我们可以解决这个问题。使用 Firebug,您可以看到资源的加载错误(如果有)。

编辑:

在web.config <system.web>部分下修改如下。

 <system.web>
  <identity impersonate="true" userName="ServerName\Administrator" password="password"/>
 </system.web>

为用户名和密码提供正确的值。您可以尝试将文件夹权限授予IIS用户组(IUSRIIS_IUSR)到托管应用程序的文件夹。(右键单击托管文件夹->选项卡PropertiesSecurity,您可以找到用户组并可以授予权限)

于 2012-10-25T03:59:55.463 回答
-1

web.config尝试在您的文件夹中放置一个文件Content。并将以下代码放入其中。

<?xml version="1.0"?>

<configuration>
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</configuration>
于 2012-10-25T04:17:02.800 回答