.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

Remove item (Cookie) from basket (Cookie Collection)

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
Hi I am busy building a shopping cart with cookies. I have datalist which I populate from the cookies with a delete button next to each cookie Here is the code:public partial class Basket_Checkout : System.Web.UI.Page { //List<ProductItemObject> ProductsList = new List<ProductItemObject>(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindList(); } } private void BindList() { dlstProducts.DataSource = null; dlstProducts.DataSource = ProductsList(); dlstProducts.DataBind(); } public List<ProductItemObject> ProductsList() { StringBuilder sb = new StringBuilder(); int loop1, loop2; HttpCookieCollection MyCookieColl; HttpCookie MyCookie; MyCookieColl = Request.Cookies; // Capture all cookie names into a string array. String[] arr1 = MyCookieColl.AllKeys; // Grab individual cookie objects by cookie name. List<ProductItemObject> CurrentBasket = new List<ProductItemObject>(); for (loop1 = 0; loop1 < arr1.Length; loop1++) { ProductItemObject item = new ProductItemObject(); MyCo

View Complete Post

More Related Resource Links

Basket with Cookie Manager

Hi, I'm trying to place products in a basket with cookies,I created this procedure:private void AggiungiShoppingCart(int ProductID, int quantita) { try { //int dayexpires = _aziendabusiness.GetDayProductMoreVendor(); if (Request.Cookies["ShoppingCart"] == null) { HttpCookie cookieshopping = new HttpCookie("ShoppingCart"); cookieshopping.Expires = DateTime.Now.AddDays(1); cookieshopping.Value = "Prodotto" + quantita + " " + ProductID.ToString(); Response.Cookies.Add(cookieshopping); } else { char[] sep = { ',' }; HttpCookie cookieshopping = (HttpCookie)Request.Cookies["ShoppingCart"]; cookieshopping.Expires = DateTime.Now.AddDays(1); string idprod = cookieshopping.Value.ToString(); string[] arrcookieshopping = idprod.Split(sep); for (int i = 0; i < arrcookieshopping.Length; i++) { if (arrcookieshopping[i].Split(' ')[1].ToString().Trim() == ProductID.ToString().Trim()) {

Forms Authentication Cookie not showing up in Request.Cookies Collection


While migrating my ASP.NET 1.1 application to 2.0, I've noticed something very odd that I can't explain:

When a user is authenticated via forms authentication, the forms authentication cookie is visible in the application trace (both in the httpheaders and the request.cookies section).  If I view the request.cookies collection using code in the application, I see the forms authentication cookie in the collection (as well as a "control" cookie I added for comparison).

If I log out of the application, the forms authentication cookie is gone and is not viewable anywhere (as expected).

Here's what's strange: When the login session of an authenticated user expires after 5 minues, the forms authentication cookie is still present.  This is expected as it is a non-persistent cookie and should remain in memory until the browser is closed.  When viewing the trace information, I see the forms authentication cookie in both the http headers and the request.cookies collection.  However, when I view the request.cookies collection from within the application using code, it is NOT there.  (The "control" cookie is, as expected)  I even took the step of reading the cookie in through javascript, and that does in fact work.

I've gone over this for hours using many

Adding a cookie to a response.redirect vs. httpWebRequest


Hello, I will try to be as clear as I can be.  I'm sure this question has been asked but I can't find a suitable answer for this particular situation.

I need to be able to redirect the browser to a new 3rd party page while at the same time supplying a cookie required for some form of authentication on the 3rd party site.

I have managed to get this to work in the following manner:


'SessionID is predetermined by another HttpWebRequest/Response  

Dim sessionCookie As New Cookie("ezproxy", sessionID.Substring(1), "/", ".someother.site")

Dim CookieJar As New CookieContainer


rRequest = HttpWebRequest.Create("where I want to go")

rRequest.CookieContainer = CookieJar

rRequest.Method = "GET"


'Make the request and get the response.

rResponse = rRequest.GetResponse()


'Save cookie(s)

If (rResponse.Cookies.Count <> 0) Then

For Each cook

Why is ASP.NET appending "\" to the beginning and end of a cookie value?


Here's what I'm seeing in FireFox when viewing a Facebook generated cookie coming from facebook:

But when I go and get this cookie and shove it into an HttpCookie object, now it's appending this stupid "\" to the beginning and end causing me all sorts of issues..one with the first key/value pair and then the uid ends up containing a "\" after the uid value (WHY would it be appending this crap?!?!?):

my code:

string facebookCookieName = "fbs_" + ConfigUtil.GetAppConfigSetting("PayPalClientID");

            // Check for an existing session
            HttpCookie facebookAuthCookie = HttpContext.Current.Request.Cookies[facebookCookieName];

string userID = facebookAuthCookie["uid"];
            string accessToken = facebookAuthCookie["\"access_token"];

How Can I Change Cookie value?

 Hi Friends, I use cookie to change the language of my website. When I click a LinkButton to change the language for first time it works but the other button doesn't work to change the language . I should delete cookie to change the language.     <asp:LinkButton ID="LinkButtonEn" runat="server" CommandArgument="en-US" OnCommand="LnkLang_Command" Text="English"></asp:LinkButton>        protected void LnkLang_Command(object sender, CommandEventArgs e)    {        Response.Cookies["mylang"].Value = "";        Response.Cookies["mylang"].Value = e.CommandArgument.ToString();        Response.Redirect("~/Default.aspx");    } thanks in advance, sepid

authentication cookie persistance

Hi All, I have set my authentication cookie persistance to true on a aspx website, this works great! Now I have made an affiliate website (HTML + iframe (same aspx)) and it does not keep my user logged in after closing browser. How can I fix this?   Thanks 

Remove action that appear in the menu which appears when we right click each individual item in libr

i need to remove or hide edit properties menu from  menu which appears when we right click each individual item in library 

To prevent the server from setting cookie on the client machine

Hi, I have deployed a Web application on IIS 6. I want to prevent my server from setting cookie on the client browser. I am using the following setting on the web.config file. < sessionState mode="InProc" cookieless="false" />  <authentication mode="Forms">   <forms loginUrl="login.aspx">     </forms>  </authentication> However, it looks like its creating a default cookie named ".ASPXAUTH" in the client machine. I dont want my application to create any sort of cookie. Is there anything specific I need to do in web.config? Please help. Thanks in Advance

Cookie is not deleted if another browser remained opened

Cookie is not deleted if another browser remained opened even the current one is closed. I also include the code to get the cookie expired . But it only works properly when user closes all browsers.  How can I resolve it ? Tks.

Best way to connect a Cookie to a session?

I usually like to do it the hard way, just to get a feel of what you can do! In ASP.net there is probably a really simple way Forms authentication etc. but this is what I have. I know from previous experience that you should never save a Cookie that contains a password, so how to connect a session to a cookie when the user accesses the website, with saved cookies information. I though about using a Guid, in the cookie, and then check the database to see if that guid is available, but this could be a sort of password like effect. Here is my code. Private Sub Login1_LoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles Login1.LoggingIn Dim mDbase As New SQL("<Server>", "<Database>", "", "", True) mDbase.Open() Dim mUserItem As UserItem = mDbase.Record.Item("SELECT TOP 1 Username, First, Surname, AccessLevel, LastVisited FROM TBLUsers WHERE Username='" & Me.Login1.UserName & "' AND Password='" & Me.Login1.Password & "'", GetType(UserItem)) If mUserItem IsNot Nothing Then If Me.Login1.RememberMeSet = True Then 'Dim mGuid As Guid = System.Guid.NewGuid 'mGuid.ToString() 'Create cookie data End If If Session("User") Is Nothin

ASP.NET Cookie Problem : Credential Cookie

Hello everybody. I am trying to create a cookie for storing Username and Password.This is so far I am :protected void Page_Load (object sender , EventArgs e) { if (!IsPostBack) { HttpCookie cookie = Request.Cookies["CredentialCookie"]; if (cookie != null) { string username = cookie.Values["Username"].ToString(); string password = cookie.Values["Password"].ToString(); TextBox Username = (TextBox) MasterLoginView.FindControl("UsernameTextBox"); TextBox Password = (TextBox) MasterLoginView.FindControl("PasswordTextBox"); CheckBox RememberMe = (CheckBox) MasterLoginView.FindControl("RemMeCheckBox"); CheckBox RemMyCred = (CheckBox) MasterLoginView.FindControl("RemMyCredentialCheckBox"); if (username != null) { Username.Text = username; } if (password != null) { Password.Text = password; } RememberMe.Checked = true; RemMyCred.Checked = true; } } } protected void LoginButton_Click (object sender , EventArgs e) { TextBox Username = (TextBox) MasterLoginView.FindControl("UsernameTextBox"); TextBox Password = (TextBox) MasterLoginView.FindControl("PasswordTextBox"); CheckBox RememberMe = (CheckBox) MasterLoginView.FindControl("RemMeCheckBox"); Label ErrorMsg = (Label) MasterLoginView.FindControl("ErrorM

Save value in cookie and retrieve it

 How can I save a variable x with the value y in a cookie k and how can I recetrive the value y ? For how long will the cookie be available? Thank you all

Sharing authentication Cookie between asp.net and sharepoint applications

Hi All, I have a requirement to share the authenication cookie between my asp.net application with sharepoint site. asp.net application and sharepoint appli are in the same domain and using the same custom authentication provider to login. I have used same cookie name and same machine key for two applications. But i could'nt see any progress.... My actual requirement is.... if i open my asp.net application and logged in, then in the next tab i will open sharepoint fba site.... then it shouldn't ask for credentials again, directly it should login with the credentials which i used for asp.net application. Thanks in advance.

Problem reading from cookie

I'm trying to build a smaller shop and I have run into some problems with cookies. This is my code in the shoppingcartaccess classprivate static string shoppingCartId { get { // get the current HttpContext HttpContext context = HttpContext.Current; // try to retrieve the cart ID from the user cookie string cartId = context.Request.Cookies["CartID"].Value; // HERE I GET THE ERROR // if the cart ID isn't in the cookie... // check if the cart ID exists as a cookie if (context.Request.Cookies["CartID"] != null) { // return the id return cartId; } else // if the cart ID doesn't exist in the cookie as well, generate // a new ID { // generate a new GUID cartId = Guid.NewGuid().ToString(); // create the cookie object and set its value HttpCookie cookie = new HttpCookie("CartID", cartId); // set the cookie's expiration date int howManyDays = SiteConfig.CartPersistDays; DateTime currentDate = DateTime.Now; TimeSpan timeSpan = new TimeSpan(howManyDays, 0, 0, 0); DateTime expirationDate = currentDate.Add(timeSpan); c

LoginView, DropDownList, Cookie, AutoPostBack Conundrum

OK, I am at a complete loss. Users for my site can have many stores to configure under their one user account. When they login I have the app generate a cookie for each store and hold all the stores basic information. For each cookie I then generate a list item in a drop down list. I can get the list to generate just fine and all of the pages that reference the list get the information fine. When I change the list to a different item however, and the page posts back my first LoginView is set to LoggedInTemplate while my navigation loginview (in site.maser like the first one) and my content loginview (in the actual page) come back in AnonymousTemplate, even though the user is authenticated. I can either do a response.redirect or physically refresh the page and all loginviews are in LoggedInTemplate again. The problem is though that I lost all of the postback data so I can essentially only view information on the first item in the dropdownlist. Now, I am new to asp.net authentication, and while I feel that I am starting to get the hang of it, there is a very good chance that I am doing something wrong. I have all the authentication working correctly and except for this postback issue. I can login, navigate through pages that aren't accessible without being authenticated and I can logout without issue. If anyone has any suggestions it would be gr

Weird problem with session cookie

Hi all,I'm having a weird problem with my web application, and I can't find the solution to it.I'm using a Java applet to read some data from an electronic ID. This applet posts its captured data to a HttpHandler class and stores the data back in some session variables. It all works smoothly, unless in some cases.Every time a do a new publish to the webserver or the website isn't touched for some time. There is a problem with the session.The applet can't find a session cookie, and so it crashes.I did some tests and indeed, the cookie ("ASP.NET_SessionId") does not exists. But it seems that other session variables (user login, etc) are working fine.To make sure that the cookie for the session ID is readable from the applet I do the following in the global.asax: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started Dim isSessionFound As Boolean = False If Response.Cookies.Count > 0 Then For Each s As String In Response.Cookies.AllKeys If s = "ASP.NET_SessionId" Then Response.Cookies("ASP.NET_SessionId").HttpOnly = False isSessionFound = True 'just for test End If Next End If End SubI tried to do something with the isSessionFound, wh
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend