无法访问外部类型错误的非静态成员 [英] cannot access non-static member of outer type error

查看:58
本文介绍了无法访问外部类型错误的非静态成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过嵌套的'ASP.login_aspx.login'错误得到'无法访问外部类型错误'ASP.login.aspx'的非静态成员。 我不知道该怎么做,如何修复。

I get a 'cannot access non-static member of outer type error 'ASP.login.aspx' via nested 'ASP.login_aspx.login' error.  I'm not sure what to do, how to fix.

这是我的代码,我在C#代码中得到错误Login1。

Here is my code, I get the error in the C# code where it says Login1.

<%@ Import Namespace="System.Data" %> 
<%@ Import Namespace="System.Configuration" %> 
<%@ Import Namespace="System.Collections" %> 
<%@ Import Namespace="System.Web" %> 
<%@ Import Namespace="System.Web.Security" %> 
<%@ Import Namespace="System.Web.UI" %> 
<%@ Import Namespace="System.Web.UI.WebControls" %> 
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %> 
<%@ Import Namespace="System.Web.UI.HtmlControls" %> 
<%@ Import Namespace="System.Data.SqlClients" %> 
<%@ Import Namespace="Weaver" %> 
<%@ Page Language="C#" %> 
 
 
 
<script runat="server"> 
//using System.Data; 
//using System.Configuration; 
//using System.Collections; 
//using System.Web; 
//using System.Web.Security; 
//using System.Web.UI; 
//using System.Web.UI.WebControls; 
//using System.Web.UI.WebControls.WebParts; 
//using System.Web.UI.HtmlControls; 
//using System.Data.SqlClient; 
 
 
    public partial class login : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, System.EventArgs e) 
        { 
 
 
 
        } 
 
 
        private bool AuthenticateUser(string uname, string password, out int userID) 
        { 
            
            bool bflag = false; 
           
            //ConfigurationManager.ConnectionStrings("DBConnectionString"); 
            string queryString = "Data Source = test; Initial Catalog = test; User Id = webservices; Password = TEST"; 
             
            string strSQL = "select * from icc_users where username ='" + uname + "' AND password ='" + password + "'"; 
           // Response.Write(strSQL); 
           // strSQL.Replace("[USERNAME]", uname); 
            //strSQL.Replace("[PASSWORD]", password); 
 
            userID = -1; 
            using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(queryString)) 
            { 
                System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(strSQL, connection); 
                connection.Open(); 
 
                System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader(); 
 
                { 
                    // Call Read before accessing data. 
                    if (reader.Read()) 
                    { 
                        userID = System.Convert.ToInt32(reader[0]); 
                        bflag = true; 
                    } 
 
                    // Call Close when done reading. 
                    reader.Close(); 
 
                } 
 
                return bflag; 
 
            } 
        } 
 
        protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e) 
        { 
 
            try 
            { 
 
                string uname = Login1.UserName.Trim(); //Get the username from the control 
 
                string password = Login1.Password.Trim(); //get the Password from the control 
                //changed 
                 
 
                int userID; 
                bool flag = AuthenticateUser(uname, password, out userID); 
 
                if (flag == true) 
                { 
 
                    e.Authenticated = true; 
                    //Changed 
                    HttpContext.Current.Session["userID"] = userID; 
                    if (password.Length > 4) 
                    { 
                        password = password.Remove(0, password.Length - 4); 
                    } 
                    HttpContext.Current.Session["password"] = password; 
                    Login1.DestinationPageUrl = "reports.aspx"; 
 
 
                } 
 
                else 
 
                    e.Authenticated = false; 
 
            } 
 
            catch (System.Exception) 
            { 
 
                e.Authenticated = false; 
 
            } 
 
        } 
 
        private bool AuthenticateUser(string uname, string password) 
        { 
            throw new System.Exception("The method or operation is not implemented."); 
        } 
    } 
} 
 
</script> 
 
 
 
<form id="Form1" runat="server"> 
<div class="content"> 
    
                <h2>LOGIN: <span></span></h2> 
 
 
<p>Welcome to online claims and customer service applications for International clients.  Once you log in, you can view the status of your claims and cases, get customer reports, send messages to HSI staff via a secure e-channel, and much more.  If you do not have a user name and password, please email us at <a href="mailto:support@us-hsi.com">support@us-hsi.com</a> </p> 
 
<h4 id="1" style="text-align: center"> 
    <br /> 
    &nbsp; 
    <asp:Login ID="Login1" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" OnAuthenticate="Login1_Authenticate1"> 
        <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" /> 
         
    </asp:Login> 
    &nbsp; 
     
    <br /> 
    <br /> 
    </h4> 
  <ul id="loginUL" runat="server"> 
         
</ul> 
 
</div> 
</form> 
 




推荐答案

看起来你混合了不同风格的ASP页面。如果您想使用
'< script runat =" server">',请不要定义类 login ,即删除
'公共部分类登录:System.Web.UI.Page   {'和不需要的'}'。 

Looks like you mix different styles of ASP pages. If you want to use ‘<script runat="server">’, then do not define the class login, i.e. remove ‘public partial class login : System.Web.UI.Page  {‘ and unneeded ‘}’. 


这篇关于无法访问外部类型错误的非静态成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆