Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

site acting strange!

$
0
0

Hi,

I have a site, when i first load it goes to main.aspx, if i try to login it will keep redirecting to the same page (won't login) until i browse some other page where it checks if the user is logged in, and since the user is not logged in it will redirect to the first page (main.aspx) then i can try to login again and this time it will work.

everything goes well after that, if i logout and try to login again, no problems but the problem will come back if i close the browser and open it again, no problems as long as the internet is open!

is this something to do with cookies? how to delete cookies when browser closes!

 protected void btnlogin_Click(object sender, EventArgs e)
    {

        UserStore<IdentityUser> userStore = new UserStore<IdentityUser>();
        userStore.Context.Database.Connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["GarageConnectionString"].ConnectionString;

        UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);

        var user = manager.Find(txtUserName.Text, txtPassword.Text);

        if (user != null && (user.UserName == "rwahdan" || user.UserName == "fhabib"))
        {

            var authinticationManager = HttpContext.Current.GetOwinContext().Authentication;
            var userIdentity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

            authinticationManager.SignIn(new AuthenticationProperties
            {

                IsPersistent = false

            }, userIdentity);
            Response.Redirect("~/Pages/Management/Index.aspx");

        }
        else
        {

            Response.Redirect("~/Main.aspx");

        }

    }

after a lot of search i realized that this is cause by Owin cookies but why is it happening and how to avoid it and still use owin? 

here is the site demo:

http://www.totahonlinestore.com/main.aspx

username: 123

password: 123456

if you try it will return back with owin backurl, go to either links on the sides then click on the product picture then on the next page click "add product", after that click on home link. now try again logging in, user 123 and pass 123456, it will!

here is the code for the "add product"

protected void btnAdd_Click(object sender, EventArgs e)
    {

        if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
        {
            string clientId = Context.User.Identity.GetUserId();
            if (clientId != null)
            {

                int id = Convert.ToInt32(Request.QueryString["id"]);
                int amount = Convert.ToInt32(ddlAmount.SelectedValue);

                cart cart = new cart
                {

                    Code = lblcode.Text,
                    AMOUNT = amount,
                    PRODUCTID = id,
                    CLIENTID = clientId,
                    DATEPURCHASED = DateTime.Now,
                    ISINCART = true,

                };

                CartModel model = new CartModel();
                lblResult.Text = model.InsertCart(cart);

               
            }
            else
            {
                Class1.productadded = 3;
            }
        }

        add_subproducts();
        Response.Redirect("~/frederic/Index.aspx");
    }

    private void add_subproducts()
    {

        if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
        {
            string clientId = Context.User.Identity.GetUserId();
            if (clientId != null)
            {

                Class1.productadded = 1;

                foreach (GridViewRow row in GridView1.Rows)
                {
                    if (row.RowType == DataControlRowType.DataRow)
                    {
                     
                        DropDownList ddlchildamount = (DropDownList)row.FindControl("DropDownList1");
                        Label thecode = (Label)row.FindControl("Label3");
                        Label theid = (Label)row.FindControl("Label1");

                        string thecode2 = thecode.Text.ToString();

                        int theid2 = Convert.ToInt32(theid.Text);

                        ChildProductModel childmodel = new ChildProductModel();
                        ChildProduct childproduct = childmodel.GetChildProduct(theid2);
                        
                        string ddl = ddlchildamount.SelectedValue;


                        if (ddl != "0")
                        {

                            int amount2 = Convert.ToInt32(ddlchildamount.SelectedValue);

                            sub_cart subcart2 = new sub_cart
                            {

                                ChildID = Convert.ToInt32(theid.Text),
                                ClientID = clientId,
                                ChildCode = thecode2,
                                ChildAmount = Convert.ToInt32(ddlchildamount.SelectedValue),
                                DatePurchased = DateTime.Now,
                                IsInCart = true,

                            };

                            SubCartModel submodel1 = new SubCartModel();
                            lblResult.Text = submodel1.InsertSubCart(subcart2);
                        }

                    }

                }

            }
        }
    }

Thanks. 


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>