locked
user profile RRS feed

  • Question

  • User-1994446809 posted

    Hello,

    I just finished designing login and sign up web forms on the website which I am currently building. I want a situation where a user will sign up or login, and upon success and redirecting to another page the user’s name should appear at the navigation bar of the next page beside navbar list items.

    That is when a user logs in, the username will be called from the database to display username information on the navigation bar.

    Here is my aspx and aspx.cs code below which I used on the project

    George

    Home.aspx :

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <title>Home</title>
    
        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet" />
        <link href="css/StyleSheet.css" rel="stylesheet" />
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
          <style type="text/css">
              .navbar{
                  width:100%;
                  !important ;
                  top:0px;
              }
              .footer {
                  width:100%;
                  !important;
              }
              .container2{
                  width:100%;
              }
              .container{
                  width:100%;
              }
    
            .title {
                line-height: 1.33;
                letter-spacing: -.5px;
                margin-bottom: 5px;
                margin-top:0%;
            }
    
            .desc {
                margin-bottom: 50px;
                margin-top: 12px;
                line-height: 1.7;
            }
    
             @media(min-width:992px){
                .col-md-6:not(:first-child) {
                }
                .col-md-6:not(:last-child) {
                    border-right:1px solid #200662;
                    border-left:1px;
                }
    
                .form-horizontal {
                line-height: 1.33;
                letter-spacing: -.5px;
                margin-bottom: 5px;
                margin-top:0%;
            }
            }
        </style>
    
        <script type="text/javascript">
    
            var image1 = new Image()
    
            image1.src = "images/1.jpg"
    
            var image2 = new Image()
    
            image2.src = "images/alex-nemo-hanse-gA3YJpTWJSs-unsplash.jpg"
    
            var image3 = new Image()
            
            image3.src = "images/QR-lady-small-o.jpg"
    
        </script>
    
    </head>
    <body style=" background-color:#DCDCDC; background-image:url('images/Dox.png'); overflow-x:hidden;">
        <form id="form1" runat="server">
            
                <div class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation" style="background-color: #00003D; font-family: Nunito;">
                    <div class="container">
                        <div class="navbar-header">
                            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse" style="background-color: #00003D; border-color:white; border-width:1px; color: white">
                                <span class="sr-only">Toggle Navigation</span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                            <a class="navbar-brand" style="color: white; font-family:Goudy Old Style;"><span><img alt="logo" src="images/JosCheck ic.jpg" height="30"/></span></a>
                            <a class="navbar-brand navbar-right"><asp:Label ID="user" runat="server" Text="User"></asp:Label></a>
                        </div>
                        <div class="navbar-collapse collapse">
                            <ul class="nav navbar-nav navbar-right">
                                <li><a href="Home.aspx" style="color: #FFFFFF">| Home</a></li>
                                <li><a href="#" style="color: #FFFFFF">| About</a></li>
                                <li class="dropdwon">
                                   <a href="#" class="dropdown-toggle" data-toggle="dropdown"style="color: #FFFFFF">| Car<b class="caret"></b></a>
                                    <ul class="dropdown-menu" style="background-color:#00003D;">
                                        <li class="dropdown-header"><a href="VehicleRegistration.aspx" style="color: #FFFFFF; background-color:#00003D;">Register Vehicle</a></li>
                                        <li class="dropdown-header"><a href="Report.aspx" style="color: #FFFFFF; background-color:#00003D;">Report</a></li>
                                        <li class="dropdown-header"><a href="Verification.aspx" style="color: #FFFFFF; background-color:#00003D;">Verify Vehicle</a></li>
                                    </ul>
                                </li>
                                <li class="dropdwon">
                                   <a href="#" class="dropdown-toggle" data-toggle="dropdown"style="color: #FFFFFF">| Phone<b class="caret"></b></a>
                                    <ul class="dropdown-menu" style="background-color:#00003D;">
                                        <li class="dropdown-header"><a href="PhoneRegistration.aspx" style="color: #FFFFFF; background-color:##00003D;">Register Phone</a></li>
                                        <li class="dropdown-header"><a href="PhoneReport.aspx" style="color: #FFFFFF; background-color:#00003D;">Report</a></li>
                                        <li class="dropdown-header"><a href="PhoneVerification.aspx" style="color: #FFFFFF; background-color:#00003D;">Phone Check</a></li>
                                    </ul>
                                </li>
                               <li class="dropdwon">
                                   <a href="#" class="dropdown-toggle" data-toggle="dropdown"style="color: #FFFFFF">| QR Code <b class="caret"></b></a>
                                    <ul class="dropdown-menu" style="background-color:#00003D;">
                                        <li class="dropdown-header"><a href="QRGenerate.aspx" style="color: #FFFFFF; background-color:#00003D;">Generate QR Code</a></li>
                                        <li class="dropdown-header"><a href="QRScan.aspx" style="color: #FFFFFF; background-color:#00003D;">Check QR Code</a></li>
                                    </ul>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            
             <div class="container" style="margin-top:3.5%; width:100%; height:470px;background-size: 100% 100%;">
                    <img alt="" class="corner" id="img" src="images/homeimg.jpg" style="height: 120%; width: 105%; margin-left:-2%;" />
                 <div class="col-xs-11" style="margin-top: 0%; color:white;">
                     <h1 style="margin-top:-30%; font-size:large; font-family:AR CENA; text-align:right; margin-right:-2.5%; font-weight:bolder;">Connect with JosCheck to Curb fraud through our eSystem</h1>
                      <p style="margin-top: -0.5%; color:white; font-size:smaller; text-align:right; margin-right:-2%;">Guard against Theft. Register your Car and Phone. Verify with QR Code</p>
                 </div>
                
                <script>
                    var step = 1
                    function slideimages() {
    
                        if (!document.images)
    
                            return
    
                        document.images.img.src = eval("image" + step + ".src")
    
                        if (step < 3)
    
                            step++
    
                        else
    
                            step = 1
    
                        setTimeout("slideimages()", 2500)
                    }
    
                    slideimages()
                </script>
               </div>&nbsp;
           <br /><br /><br />
            <div class="container-fluid">
                    <div style="text-align: center;">
                        <img src="images/chain.png" alt="iphone" />
                    </div>
                <h1 style="font-size: xx-large; font-family: Goudy Old Style; color: #200662; text-align: center; font-weight: bolder;">Curbing Fraud on All Angles</h1>
                <p style="font-size: small; font-family: Verdana; text-align: center; width: 60%; margin: 1em auto 2em auto;">
                    The predominant discourse, familiar since from the 1990s, emphasizes infrastructure as one of the principal entities in a global
                system of development. The process of moving a society from a traditional subsistent level towards a modern and scientific
                stage is one of the most perplexing issues facing many nations in the developing world. What is at hand is a conflict between the 
                seemingly non-dynamic forces of traditions and the systematic growth orientation of modernization (Myrdal, 1970). Given these conditions, the 
                process of promoting development is essentially one of organizing and combining various elements in what Mosher terms the 'institutional 
                milieu' of development [1966. 1976]. These elements consist of a nation’s customs and traditions, ideology, physical resources and education.
                </p>
                &nbsp;&nbsp;
            </div>
            <div class="container-fluid" style="background-color:#00003D;">
                <h1 style="color:#eeeeee; text-align:center;">eFeatures</h1>
                
                 <div class="row" style="margin-left:0%;">
              <div class="section">
                  <div class="col-md-4" style="border-style:groove; border-width:1px; border-radius:8px;"><br />
                       <img src="images/2018-Mercedes-Benz-C-300-Sedan.png" alt="Toyota-2016-Lineup" width="200" height="100"/>
                      <br /><br />
                      <h2 style="color:#eeeeee; margin-top: 0; font-size: x-large; font-family:Arial Rounded MT; font-weight:bolder;">Car Verification</h2>
                      <p style="color:#eeeeee; width:70%;">Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. </p>
                      <p><a class="btn btn-primary" href="#" role="button">Read More &raquo;</a></p>
                  </div>
                  </div>
    
              <div class="col-md-4" style="border:thin solid #000000; border-color:white; border-radius:8px;"><br />
                  <img src="images/smartphone-png-1.png" alt="smartphone" width="100" height="100"/>
                  <br /><br />
                  <h2 style="color:#eeeeee; margin-top: 0; font-size: x-large; font-family:Arial Rounded MT; font-weight:bolder;">Phone (IMEI) Verification</h2>
                  <p style=" color: #eeeeee; width:70%;">Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
                  <p><a class="btn btn-primary" href="#" role="button">Read More &raquo;</a></p>
              </div>
    
              <div class="col-md-4" style="border-style:groove; border-width:1px; border-radius:8px; margin-right:0%;"><br />
                    <img src="images/red%20QR.jpg" alt="redqr" width="80" height="80"/>
                  <br /><br /><br />
                  <h2 style="color: #eeeeee; margin-top: 0; font-size: x-large; font-family:Arial Rounded MT; font-weight:bolder;">QR Code Generation & Verification</h2>
                  <p style=" color:#eeeeee; width:80%;">Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper.  Ut fermentum justo sit amet risus.</p>
                  <p><a class="btn btn-primary" href="#" role="button">Read More &raquo;</a></p>&nbsp;
              </div>
            </div><br /> <br />
            </div>
            <br /><br /> <br /><br />
             <div class="container-fluid">
                    <div class="row">
                         <div class="form-horizontal col-md-6">
                             <div class="form-group">
                                 <h1 style="font-size: x-large; color: #200662; margin-top: 4%; margin-left:20%; font-family: Co Headline Corp;">Why QR Code?</h1>
                                 <p style="font-size: small; width: 60%; margin-left:20%; font-family: Lucida Sans Unicode">
                                     QR Codes are 2D codes that data is embedded into
                                The QR stands for Quick Response. It has the capacity to store as many data as possible and can be used on all platforms
                                to curb fake - On Reciepts, Certificates, Identification cards, Tickets, and can also be used to make payment transactions.
                                The QR is the safest mode of information storage, as it cannot be reversed once generated, and are not the same.
                                 </p>
                             </div>
                        </div>
                        <div class="col-md-6" style="margin-top:0%; margin-left:0%;">
                            <img src="images/Img%20QR.jpg" class="image-fluid" width="320" height="220" />
                        </div>
                    </div>
                </div>
            <br /><br /><br /> <br /> <br />
            <div class="container-fluid" style="background-color:#eeeeee;"><br />
                <h1 style="font-family:Tahoma; font-size:larger; text-align:center;">- Joscheck Authencity Drive -</h1>
                <p style="font-family:AR CENA; font-size:medium; width:50%; margin-left:25%;">The predominant discourse, familiar since from the 1990s,
                system of development. The process of moving a society from a traditional subsistent level towards a modern and scientific
                stage is one of the most perplexing issues facing many nations in the developing world. What is at hand is a conflict between the 
                seemingly non-dynamic forces of traditions and the systematic growth orientation of modernization (Myrdal, 1970). Given these conditions, the 
                process of promoting development is essentially one of organizing and combining various elements in what Mosher terms the 'institutional 
                milieu' of development [1966. 1976]. These elements consist of a nation’s customs and traditions, ideology, physical resources and education.</p>
                <br /><br /><br /><br />
            </div>
    
            <footer>
                <div class="container" style="background-color: #696969; height: 285px; margin-bottom:0px; font-family:Goudy Old Style; font-size:medium;">
                    <p class="pull-right"><a href="#" style="color: white;">Back to Top</a></p>
                    <p style="color: white;"><a href="Home.aspx" style="color: white;">Home</a> &middot; <a href="#" style="color: white;">About</a></p>
                    <div class="container-fluid" style="text-align: center;">
                        <p style="color: white;  font-size: medium; margin-top: 3%; margin-left:0%;">Contact Address: Nigerian Merit Award House</p>
                        <p style="color: white;  font-size: medium;">Maitama District Abuja, F.C.T</p>
                        <p style="color: white;  font-size: medium;">08138709222 08037445843 08023456781</p>
                        
                         <asp:HyperLink ID="HyperLink5" runat="server" ImageUrl="~/images/facebook%20color.png" imagesize="20" NavigateUrl="http://www.facebook.com">HyperLink</asp:HyperLink>
                        <asp:HyperLink ID="HyperLink6" runat="server" ImageUrl="~/images/Gmail-icon.png" NavigateUrl="http://www.gmail.com">HyperLink</asp:HyperLink>
                        <asp:HyperLink ID="HyperLink7" runat="server" ImageUrl="~/images/linkedIn%20color.png" NavigateUrl="http://www.linkedin.com">HyperLink</asp:HyperLink>
                        <asp:HyperLink ID="HyperLink8" runat="server" ImageUrl="~/images/whatsapp%20green.png" image-size="30px" NavigateUrl="http://www.whatsapp.com">HyperLink</asp:HyperLink>
                    </div>
                    <br />
                    <br />
                    <p style="color: white; margin-bottom:-4%; font-weight:bold;">Copyright &copy; 2020 Joscheck Tech. All Rights Reserved.</p>
                </div>
            </footer>
        </form>
        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="js/bootstrap.min.js"></script>
    </body>
    </html>

    Home.aspx.cs :

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.Security;
    using System.Xml.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.SqlClient;
    
    public partial class Admin : System.Web.UI.Page
    {
        SqlCommand cmd = new SqlCommand();
        SqlConnection con = new SqlConnection();
        SqlDataAdapter sda = new SqlDataAdapter();
        DataSet ds = new DataSet();
    
        protected void Page_Load(object sender, EventArgs e)
        {
            con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True";
            con.Open();
            showdata();
        }
    
        public void showdata()
        {
            cmd.CommandText = "select * from Login where user_name='" + Session["user"] + "'";
            cmd.Connection = con;
            sda.SelectCommand = cmd;
            sda.Fill(ds);
            user.Text = ds.Tables[0].Rows[0]["user_name"].ToString();
        }
    }

    Login.aspx :

    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <title>Login</title>
    
        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet" />
        <link href="css/StyleSheet.css" rel="stylesheet" />
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
        <style type="text/css">
            .center-page {
                width:300px;
                height:300px;
                ;
    
                top:0;
                bottom:0;
                left:0;
                right:0;
    
                margin:auto;
            }
     
        </style>
    
    </head>
    <body style=" background-color:#DCDCDC; background-image: url('images/main.jpg'); background-size:cover; overflow-x:no-display;">
        <form id="form1" runat="server">
        
            <div class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation" style="background-color:#00003D; font-family:Nunito;">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse" style="background-color:#00003D;border-color:white; border-width:1px;color:white">
                        <span class="sr-only">Toggle Navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                   <a class="navbar-brand" style="color: white">Login</a>
                </div>
                <div class="navbar-collapse collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="JosCheck.aspx" style="color: #FFFFFF">| Home</a></li>
                        <li><a href="#" style="color: #FFFFFF">| About</a></li>
                          <li><a href="SignUp.aspx" style="color: #FFFFFF">| Sign Up</a></li>
                    </ul>
                </div>
            </div>
        </div>
       
            <div class="container-fluid">
                <div class="center-page" style="margin-top: 10%; border: thin solid #000000; border-color: lightgray; border-radius: 8px; width: 40%;">
                    <div class="center-page">
                        <h1 style="font-size: x-large; font-family: Co Headline Corp; color: red;">Login</h1>
                        <p style="margin-top: -7%;">____________________________</p>
                        <br />
                        <div class="col-xs-11" style="margin-left: -12%;">
                            <asp:Label ID="Label1" ForeColor="#200662" runat="server" Font-Bold="true" CssClass="col-md-2 control-label" Text="USERNAME"></asp:Label>
                            <div class="col-xs-11">
                                <asp:TextBox ID="Username" CssClass="form-control" Width="350px" BorderStyle="None" runat="server" placeholder="Username"></asp:TextBox>
                            </div>
                        </div>
    
    
                        <div class="col-xs-11" style="margin-top: 20px; margin-left: -12%;">
                            <asp:Label ID="Label2" ForeColor="#200662" runat="server" Font-Bold="true" CssClass="col-md-2 control-label" Text="PASSWORD"></asp:Label>
                            <div class="col-xs-11">
                                <asp:TextBox ID="Password" CssClass="form-control" Width="350px" BorderStyle="None" runat="server" placeholder="Password" TextMode="Password"></asp:TextBox>
                            </div>
                        </div>
    
                        <div class="col-xs-11" style="margin-top: 20px; margin-left: -12%;">
                            <div class="row">
                                &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                            <asp:Button ID="Button1" runat="server" Text="Login" Font-Size="larger" Class="btn btn-success" OnClick="Button1_Click" />
                                &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <asp:HyperLink ID="HyperLink1" runat="server" href="SignUp.aspx" Font-Bold="true" Font-Size="medium" ForeColor="red">SIGN UP HERE</asp:HyperLink>
                            </div>
                        </div>
                        <div class="col-xs-11" style="margin-top: 10px; margin-left: -12%;">
                            &nbsp;&nbsp;&nbsp;
                           <asp:Label ID="Label7" runat="server"></asp:Label>
                        </div>
                    </div>
                </div>
            </div>
               
            <footer>
                <div class="navbar-fixed-bottom" style="background-color:#696969; width:auto; margin-top:0%;">
                    <p style="color: white;"><a href="Homepage.aspx" style="color: white;">Home</a> &middot</p>
                    <p style="color: white; text-align: center;">Copyright &copy; 2020 Joscheck Tech. All Rights Reserved.</p>
                </div>
            </footer>
        </form>
         <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="js/bootstrap.min.js"></script>
    </body>
    </html>

    Login.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Data;
    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 Homepage : System.Web.UI.Page
    {
        SqlDataAdapter sda = new SqlDataAdapter();
        DataSet ds = new DataSet();
        SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True");
       
        protected void Page_Load(object sender, EventArgs e)
        {
            //Label7.Dispose();
          //  Label7.Visible = false;
        }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Username.Text != "" & Password.Text != "")
                {
                    string check = "select count(*) from [Login] where user_name = '" + Username.Text + "' and pass = '" + Password.Text + "' ";
                    SqlCommand com = new SqlCommand(check, con);
                    con.Open();
                    int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
                    con.Close();
    
                    if (temp == 1)
                    {
                        Username.Text = "";
                        Password.Text = "";
                    con.Open();
                    string user = Username.Text.Trim();
                    com.CommandText = "select * from Login where user_name='" + Username.Text + "'";
                    com.Connection = con;
                    sda.SelectCommand = com;
                    sda.Fill(ds, "detail");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        Session["user"] = user;
                        Response.Redirect("Home.aspx");
                        con.Close();
                    }
                }
    
                    else
                    {
                        Label7.ForeColor = System.Drawing.Color.Red;
                        Label7.Text = "Invalid Username or Password";
                        Username.Text = "";
                        Password.Text = "";
                    }
                }
            else
            {
                Label7.ForeColor = System.Drawing.Color.Red;
                Label7.Text = "Empty Data";
            }
        }
    }

    Sunday, April 26, 2020 9:12 PM

Answers

  • User1535942433 posted

    Hi georgeakpan233,

    According to your description and code,I find the same case with others in the forums.I suggest you could refer  to https://forums.asp.net/t/2166353.aspx.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 27, 2020 6:45 AM

All replies

  • User475983607 posted

    Frankly, this programming problem has been solved a long long time ago.  Session has not be used to store user login and handle security since the 90s. 

    Visual Studio comes with templates and APIs that generates all the code you need for managing user accounts using modern standards.  While I think it is cool you're building you own custom security, it's best to follow industry standards.  With that being said, create a new Forms Project and select the "Individual Account" option when presented with Authentication options.  Take a look at the code and read the reference documentation.

    Being that you've posted in the "Getting Started" forum, I recommend going with MVC or ASP.NET Core.  While Web Forms is a wonderful framework, Core is where all the new and exciting developemnt is happening.

    Sunday, April 26, 2020 10:35 PM
  • User1535942433 posted

    Hi georgeakpan233,

    According to your description and code,I find the same case with others in the forums.I suggest you could refer  to https://forums.asp.net/t/2166353.aspx.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 27, 2020 6:45 AM
  • User-1994446809 posted

    Re: user profile

    a few seconds ago|LINK|105.112.117.25

    Hello Yijing Sun,

    I referred to the link you directed me to and tried to use the sample code in the demo, but it gave me an error from Home code-behind:  (Home.aspx.cs) which stated thus; 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    The error message in the browser was this:

     str = System.Configuration.ConfigurationManager.ConnectionStrings["aspnet-TestApplicationWithDatabase-20190820030542"].ConnectionString;

    So I changed the str to this and still had the error

    str = System.Configuration.ConfigurationManager.ConnectionStrings["Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"].ConnectionString;

    I thought that maybe the connecting string was different which is why i changed it. 

    -George Akpan

    Monday, April 27, 2020 8:38 PM
  • User-1994446809 posted

    Hello Yijing Sun,

    I referred to the link you directed me to and tried to use the sample code in the demo, but it gave me an error from Home code-behind:  (Home.aspx.cs) which stated thus; 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    The error message in the browser was this:

     str = System.Configuration.ConfigurationManager.ConnectionStrings["aspnet-TestApplicationWithDatabase-20190820030542"].ConnectionString;

    So I changed the str to this and still had the error

    str = System.Configuration.ConfigurationManager.ConnectionStrings["Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Dataregister.mdf;Integrated Security=True"].ConnectionString;

    I thought that maybe the connecting string was different which is why i changed it. 

    -George Akpan

    Monday, April 27, 2020 8:40 PM