我用localhost的时候,当session失效时,会自动跳转到登陆页面,这个是正常的,当用IP地址访问的时候,就会出现“为将对象引用设置到对象的实例”,到底是什么原因啊,能帮忙解决下吗

解决方案 »

  1.   

    估计你在Web.config文件中,将地址写死成localhost了,贴出你的Web.Config文件来看一下。
      

  2.   

    <?xml version="1.0"?>
    <!--
      有关如何配置 ASP.NET 应用程序的详细信息,请访问
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
    <connectionStrings>
    <add name="hqglDatabaseStr" connectionString="data source=localhost;Initial Catalog=sd;User ID=sa;Password=801226" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
    <compilation debug="true" targetFramework="4.0"/>
        <sessionState mode ="StateServer" cookieless="true" timeout="20"/>
           <authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="2"/>
    </authentication>
    <membership>
    <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    </providers>
    </membership>
    <profile>
    <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    </providers>
    </profile>
    <roleManager enabled="false">
    <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
    </providers>
    </roleManager>
    </system.web>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    </configuration>
      

  3.   

    <?xml version="1.0"?>
    <!--
      有关如何配置 ASP.NET 应用程序的详细信息,请访问
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
    <connectionStrings>
    <add name="hqglDatabaseStr" connectionString="data source=localhost;Initial Catalog=sd;User ID=sa;Password=801226" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
    <compilation debug="true" targetFramework="4.0"/>
        <sessionState mode="InProc" cookieless="true" timeout="20"/>
           <authentication mode="Forms">
    <forms loginUrl="~/Account/Login.aspx" timeout="2"/>
    </authentication>
    <membership>
    <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
    </providers>
    </membership>
    <profile>
    <providers>
    <clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    </providers>
    </profile>
    <roleManager enabled="false">
    <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
    </providers>
    </roleManager>
    </system.web>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    </configuration>
      

  4.   

    在你的另外一个帖子里已经回答过了,你可以试一试:http://topic.csdn.net/u/20110921/16/7a1fdf0e-f98b-44cf-8d25-409ce74743bc.html?seed=1886894976&r=75642625#r_75642625
    另外在web.config中添加 <customErrors defaultRedirect="Login.aspx" mode="On"/>,页面有错误时会自动跳转到首页。
      

  5.   

    是否程序中未判断Session[""] 是否为null
      

  6.   

    if(session[""]==null){
    跳转到登陆页面
    }