本帖最后由 sosaw18 于 2010-05-23 23:41:30 编辑

解决方案 »

  1.   

    数据连接不要用Windows集成验证,用sql用户名密码验证。
    windows集成身份验证会使用当前进程的启动帐号登录数据库,iis中,它就是'NT AUTHORITY\NETWORK SERVICE',导致无法登陆数据库。
      

  2.   

    已经设置了,我是在 VS 2008 中设置的,网站 — ASP。NET 设置中,选择身份验证 — 通过 Internet, 还是不行啊!
    我的 SQL Server 是用的 Sa 账户登录的。
      

  3.   

    你的报错信息,说明你没有用sa登录,最好去查看下所有new connection的地方,是不是使用了统一的连接串。很有可能有地方hardcoding了
      

  4.   

    你给你的SQLSERVER添加用户   'NT   AUTHORITY\NETWORK   SERVICE ' 不就好了?就在那个安全性的栏目中。
      

  5.   

    上面各位提到的 'NT AUTHORITY\NETWORK SERVICE ' 账户原来 SQL Server 中就存在, 默认数据库是 Master, 真是让人费解, 继续麻烦各位解答.
      

  6.   

    你是指 Web.config 文件中吗?
      

  7.   

    我把数据库项下的安全性里的用户建立了,设定了权限,同样在针对网站建立的数据库项下的安全性-用户里也建立了 'NT AUTHORITY\NETWORK SERVICE ' 并设定了权限,依然没有改观。
      

  8.   

    和你说半天就说不通。你100%有地方链接数据库用了windows集成认证。自己好好检查所有创建Sqlconnection实例的地方,你绝对能找得到VS2008调试ok,那是因为vs2008的asp.net develepment server是用当前账户启动的,它访问数据库用的是当前登录用户,所以可以登录成功。你部署的server上是iis来跑你的网站,'NT AUTHORITY\NETWORK SERVICE'用的就是这个系统内置账户。
    当你iis和db不是一台服务器的时候,就算把这个用户加进去也没用,不同机器的内置账户的sid也是不同的。
      

  9.   

    我的 iis 和 db 在一台服务器上, 为了研究这个问题, 我新建了一个网站, 只有登录控件, 没有 Sqlconnection 实例, 哪里有 windows 集成验证, Sql Server  是 Sa 用户, 网站 .NET 设置是通过 Internet, 问题在那呢.
      

  10.   

    1 数据库有没有启用集成身份认证?
    2 Web.config里的数据库连接字符串是不是sa帐号登录?
      

  11.   

    数据库里没有启用集成身份验证,  web.config 文件内容全部粘贴如下:<?xml version="1.0"?>
    <!-- 
        注意: 除了手动编辑此文件以外,您还可以使用 
        Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
         “网站”->“Asp.Net 配置”选项。
        设置和注释的完整列表在 
        machine.config.comments 中,该文件通常位于 
        \Windows\Microsoft.Net\Framework\v2.x\Config 中
    -->
    <configuration>
    <configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
    </sectionGroup>
    </sectionGroup>
    </sectionGroup>
    </configSections>
    <appSettings/>
    <connectionStrings/>
    <system.web>
    <customErrors mode="Off"/>
    <!-- 
                设置 compilation debug="true" 可将调试符号插入
                已编译的页面中。但由于这会 
                影响性能,因此只在开发过程中将此值 
                设置为 true。
            -->
    <roleManager enabled="true"/>
    <compilation debug="true">
    <assemblies>
    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
    </compilation>
    <!--
                通过 <authentication> 节可以配置 ASP.NET 用来 
                识别进入用户的
                安全身份验证模式。 
            -->
    <authentication mode="Forms"/>
    <!--
                如果在执行请求的过程中出现未处理的错误,
                则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
                开发人员通过该节可以配置
                要显示的 html 错误页
                以代替错误堆栈跟踪。        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
    <pages>
    <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </controls>
    </pages>
    <httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    </httpHandlers>
    <httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
    </system.web>
    <system.codedom>
    <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="WarnAsError" value="false"/>
    </compiler>
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
    <providerOption name="CompilerVersion" value="v3.5"/>
    <providerOption name="OptionInfer" value="true"/>
    <providerOption name="WarnAsError" value="false"/>
    </compiler>
    </compilers>
    </system.codedom>
    <!-- 
            在 Internet 信息服务 7.0 下运行 ASP.NET AJAX 需要 system.webServer
            节。对早期版本的 IIS 来说则不需要此节。
        -->
    <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
    <remove name="ScriptModule"/>
    <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </modules>
    <handlers>
    <remove name="WebServiceHandlerFactory-Integrated"/>
    <remove name="ScriptHandlerFactory"/>
    <remove name="ScriptHandlerFactoryAppServices"/>
    <remove name="ScriptResource"/>
    <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>
    </system.webServer>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    </configuration>
      

  12.   

    你都没有<connectionStrings/>连接数据库的语句,那你想说什么呀?这样当然什么都没有了
    重新捋一下吧,你是想用login控件吗?那么login的控件是确实知道是怎么用的么?--------
    在很久以前,各个网站开发的人都会自己做一套用户认证的功能,但每个人的实现都不同,暴露出各种问题,比如安全,比如学习成本等等。所以微软给我们提供了一套统一的认证方式,就是Membership,他还提供角色管理,个性化,会话状态,站点地图等功能,都是通过提供程序来实现,并且很容易扩展,只是统一了接口。并且微软还为我们提供了一个SqlServer存储用户认证的实现,在统一接口的基础上,控件才得以实现,所以就有了login等一系列控件。但是sqlserver的默认实现不是通过sa登陆,而是直接用自己登陆windows系统的帐号登录数据库,这样如果你在vs里用是正常的,但在iis里独立访问数据库就出现权限问题了,所以你要修改你的数据库访问方式
      

  13.   

    你想修改什么?让他能在iis上运行正常?那是要配置了,不是修改代码,其实你的代码已经正确了呀。
      

  14.   

    我的做法是:在VS2008中新建网站,里面缺省有一个网页,default.aspx, 我新添加一个网页,命名为:login.aspx, 在其中加入 login 控件,没有对该控件属性作任何设置。然后点选 VS2008的网站-ASP.NET 配置菜单项目,在新打开的Internet explorer 窗口中的“安全”选项下,设置身份验证为通过 Internet, 接下来新建用户,之后在VS2008 中运行调试 login.aspx,在打开的网页中输入用户名和密码,顺利通过,页面跳到 default.aspx 页面,然后,把其放到 iis 下,建立网站,从外网调用,login.aspx 刷新一下,提示“您的登录尝试不成功。请重试。”,怎么页无法通过。
      

  15.   

    那么你知道不知道在你点选 VS2008的网站-ASP.NET 配置菜单项目,在新打开的Internet explorer 窗口中的“安全”选项下,设置身份验证为通过 Internet的时候,系统自动给你做了什么?
    他在你的App_Data目录下建立一个一个ASPNETDB.MDF文件,这个是SqlServer数据库,并且在你的web.config里做了修改,还加了一条    <add name="ApplicationServices"
             connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
             providerName="System.Data.SqlClient" />
    数据库连接的话。如果你要到iis里也正常,那么你要把这个数据库放到服务器上的sqlserver去,并且还可能需要修改上面这个连接字符串。
      

  16.   

    因为在VS2008中调试没问题,而在外部应用就有问题,我不知是不是<authentication mode="Forms"/>
    的原因。
      

  17.   

    说错了。<compilation debug="true">是不是这个的原因?
      

  18.   

    怎么我找遍了 Web.config 文件都没有发现你写的连接语句,是不是问题出在这里.
      

  19.   

    app_data里有aspnetdb数据库么?web.config应该是有链接的,不然怎么可能把你的数据存到数据库呢,是不是你发布来发布去看错文件夹了?
      

  20.   

    当然有 aspnetdb 数据库, 也打开浏览过, 存在建立的用户名, 肯定不会菜到那个地步, 但确实在 web.config 文件里面没有任何有关数据库的连接.我现在真希望你把我的过程在你的系统里走一遍, 看有没有类似的问题, 谢谢你这么耐心的解答!
      

  21.   

    我想起来了,你可能是这个情况在 %SystemRoot%\Microsoft.NET\Framework\<版本>\CONFIG 目录下的 Machine.config 和 Web.config 文件里有定义链接字符串的,它是最根的文件,你是直接用他的链接,所以自己的web.config里没有。在iis的站点,属性里,asp.net选项卡里有定义LocalSqlServer这个链接。
    data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true在服务器上,你还是需要自己重新写这个链接的
      

  22.   

    在自己的 <connectionStrings/> 里做一个自己的链接,记得是用sa登录的那种
    修改这节
    <system.web> <membership>  <providers>        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />  </providers> </membership></system.web>
    里面的connectionStringName="LocalSqlServer" 为你自己的链接名称,不要用LocalSqlServer。不过我在你提供的web.config里面有看到membership,这个是真不可能的,你确定你发上来的是你最后保存的文件么?