C# - How To Browser Occasionally Losing HttpCookie For Authentication After Postback And Redirect

Dec 29, 2010

This has been a nagging issue for some time, but very sporadic and difficult to isolate.

From time to time, browsers that have authenticated on a web application, have been open for a while, have logged in and out of the same web application multiple times, have multiple tabs, are pretty much any browser (Chrome, IE, Firefox, Safari), and seemingly at random, lose their ability to retain an AuthCookie after being set and followed by a redirect. Closing the browser and starting a new session resolves the issue, as does opening up a different browser and attempting to authenticate.

Our team uses forms authentication for all of our websites and web application. This is a pretty typical setup where a login form is displayed, the user enters credentials and a cookie is set on the click event of the postback, then a redirect occurs to the same page where the cookie is then referenced and used to complete authentication.

In this situation

FormsAuthentication.FormsCookieName = ".WebAuth"

Within Event:

FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, Username, DateTime.Now, DateTime.Now.AddMinutes(SessionTimeout), false, Username); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
Response.Cookies.Add(faCookie);
Response.Redirect(Request.RawUrl, true);
After the redirect, on PreInit:
HttpCookie authCookie = Request.Cookies[cookieName];

At this point, the authCookie variable is typically not null, but in these isolated circumstances that I've outlined above, the cookie comes back null after the redirect.

This happens very randomly, sometimes weeks before affecting one of our developers. As I said, restarting the browser resolves the issue.

Today I had it happen on our dev server while using Chrome. I had logged into the application, allowed the application to session timeout, and then attempted to login again. The attempted login then failed to set the cookie. I remotely attached Visual Studio to the process on the server to begin debugging. The entire time I could step through my code, even deploy new code versions to the server with updates, restart the app, restart IIS on the server, attach and reattach to the project, and the issue persisted in Chrome. In Firefox, I was able to authenticate without issue.

From Chrome, the login would validate, attempt to set a Response Cookie as outlined above. Prior to redirect, I could see the properly set Response Cookie, as well as its counterpart in the Request Cookies. However, on each redirect after a seemingly successful login, the Response and Request Cookie are gone.

I enabled Trace on the application to view the cookie collection:

There is a .WebAuth in the Request Cookies Collection, as well as ASP.NET_SessionId and several ASPSESSIONIDxxxxxxxx, but when the page loads, only the ASP.NET_SessionId and ASPSESSIONIDxxxxxxxx cookies are available in the Request.Cookies scope, no sign of the .WebAuth. However, in the page's Trace information after render, there multiple .WebAuth cookies listed, it is just that the page seems to have no access to them.

Primarily, on a working version after authentication there is both a .WebAuth Response and Request Cookie in the page's Trace info. But on a non functioning browser window, the Response Cookie is absent.

Has anyone else had any experience with this? It is such a nagging issue, and so sporadic, but I would love to be able to resolve it. My concern is that it may be affecting users and we would have no knowledge since the description of the issue is so convoluted.

View 1 Replies


Similar Messages:

Visual Studio :: Losing Session When Debugging After Redirect?

Mar 14, 2011

OS: Windows 7

VS: VS 2010 Pro SP1 - IIS Express

I am debugging my project, the first page is a login page which I login and I can see from debug that the session is being set, after the redirect to the homepage the session seems to be lost and I am taken back to the login page.

If I run outside of VS on our sandbox or production server the login works fine. It only seems to be my machine w/ VS that does not like the sessions.

View 2 Replies

Security :: Losing Persistence Using Forms Authentication?

Feb 13, 2011

I have had a website on a shared web hosting plan for over a year with no issues with keeping persistence. It's been prettys stable, and the only drawback of the host I am using is that it's very slow on occasion...sometimes taking 5-10 seconds to load a page.

So over the last few weeks, I went searching for another web host and and testing one out now.So while my existing website is still running the old web host, I copied the code and data and pushed it on the new web host. It's up and running, but I noticed that shortly after I log in (Forms Authentication), I am logged off within 20-30 seconds.I decided to add the machineKey to the web.config, and it seems to have fixed it.

My question is why would this have fixed it? I asked if the host's servers were in a web farm.

View 5 Replies

State Management :: Losing Session Data With Response.Redirect?

Oct 25, 2010

This is weird. In my newly developed chat application, when I invoke Response.Redirect, I am losing my session data. What is particualrly odd is that this sometimes seems to occur after a slight delay, so I reach the page, and then the session info gets lost momentarily thereafter. Mostly though it seems to get lost immediately. I have of course googled this issue, but yet to find anything that speaks to my problem. SessionState is in InProc mode. Session state has been working fine for me until this unexpected problem, so everything is configured right. So far the only workaround I can think of is to use a link instead of a button, and use javascript to call a server-side function on onclick to do the work I need to do before the link gets invoked. Messy, and I'd rather not go that way unless there's no alternative.

Just to preempt one red herring, I do use Response.Redirect(<address>, false).

The problem occurs both on the testing and production servers. I'm running ASP.NET 3.5 on IIS7.

View 1 Replies

An Always Up-to-date Shopping-cart Without Losing The Browser-history?

Dec 17, 2010

I am trying to make a website with on each page the same shopping-cart.When a client presses on his browser's back, forward or refresh button, the shopping-cart should always be up-to-date and not change.And this all without receiving the ugly "webpage is expired" message!And not using php!)I thought it would be easy to find an example for this kind of website, but.... no!

View 20 Replies

C# - Losing The Session After The Postback?

Sep 1, 2010

I have been using session variables in my asp.net application for passing the next property:

[DefaultValue(true)]
public bool IsModificationMode
{
get
{
return (bool)Session["ModificationMode"];
}
set { Session["ModificationMode"] = value; }
}

In the PageLoad, I set it's value.

Now after the Postback, I am losing it's value having a a NullReferenceException

View 4 Replies

Losing Textbox Value On Postback?

Jun 9, 2010

In a page I have a link; clicking on it opens a dialog and sets a textbox value for that dialog.

However, once I click on submit in that dialog, the textbox value is null.

Link:

<a href="#" onclick="javascript:expand('https://me.yahoo.com');
jQuery('#openiddialog').dialog('open'); return false;">
<img id="yahoo" class="spacehw" src="/Content/Images/spacer.gif" /></a>

[Code].....

View 2 Replies

Web Forms :: Losing Data Across Postback?

Feb 19, 2010

I have an upload control (csv file) of which I use the stream to retrieve data in a datatable that I then bind to a datagrid, sitting in a repeater control.I have to bind more than one record to the repeater, therefore I need to find a way of storing the stream for each binding, so that I can bind it to the datagrid again, via itemdatabound event of repeater.

I have tried storing the stream in the repeater's datatable but on each postback, the content of the stream gets lost. The stream still exists, but its length is set to 0.I have tried storing it in a session object, but again it is reset to 0.

I have tried using viewstate but I get a xmlserialization error. Saying IXmlSerialization is not implemented.I am desperate to find a work around as I am feeling the pressure at work.

View 3 Replies

Hidden Field Losing Its Value On Postback?

Jun 7, 2010

I have a ascx page where I am using a hidden field to store the value of a the drop down box as it is generated using a google address finder. My problem is that when I try to store the value directly in the hidden field :

hfDdlVerifyID.Value = ddlVerifySS.SelectedValue;

in the event of a button click, the value is stored but on postback is lost again. Whereas, if i try to use Scriptmanager to do it, nothing is stored.

getBuild.AppendLine("$get('" + hfDdlVerifyID.ClientID + "').value = $get('" + ddlVerifySS.ClientID + ").value;");
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "storeHidden", getBuild.ToString(), true);
// Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "storeHidden", getBuild.ToString(), true);
string test = hfDdlVerifyID.Value.ToString();

[Code].....

View 1 Replies

Losing Most Of The Page Content On Second Postback?

Jul 5, 2010

I have a form with a update panel. This posts the form and validates it. Returning a errorMessage string of any invalid field such as "Field xyz is a required field, Field abc needs to be a quantity"

When I enter incorrect date it posts back fine and displays the text in a div at the bottom of the page which the update panel is aimed at to update. (and only this it should be changing)

This works but the second time I hit say (say i enter invalid data twice) the Complete form will disappear leaving me with just the banner of the site and the error message that is returned.

Ive tried commenting out the entire of the code post back so that the button doesn't actually do anything but it still has the same problem(of course this time it wouldnt have a error message created)

So i can only think it is something to do with the updatepanel itself and how it works but i have been staring at this for ages and have no more ideas!

View 2 Replies

State Management :: Losing Data Between Postback?

Mar 27, 2010

I am in beginner level on developing web pages. I was coding on desktop applications and as you know it is easy to say that web applications are extremely different than desktop applications.

I wonder why data are lost between postbacks.???? And what is the best way not to lose the data belonging to a specific control (especially gridview). Session or viewstate or anything else?

View 10 Replies

State Management :: Literal Losing Value On PostBack?

Dec 13, 2010

Never had this happen before. I just upgraded my site from 3.5 to 4.0. Here's the scenario:

1.) I have a literal on a web form, in an UpdatePanel.

2.) On PostBack, the Literal's "Text" property loses it's value. The ViewState is enabled throughout the page. Further, I changed the Literal to a label and it also has this problem. The TextBox's appear to keep their values.

3.) If I remove all of the Ajax controls (which currently is just the UpdatePanel and the ScriptManager) then the Literal control keeps it's value through PostBacks.

4.) There is no client side JavaScript where I'm manually changing the values of these controls. They are only editted in the server side events.

I have read that setting the AutomaticDataBind property in the web.config could remedy this but I can't find any documentation on it and I don't know where to put it in the web.config to even try it.

View 7 Replies

AJAX :: CascadingDropDown Losing Selected Value On PostBack?

Nov 19, 2010

I am using the AJAX Contol Toolkit and 4 CascadingDropDown extenders with an ODBC connection in a Web Service. The original load of values in each level works great. I then use these values to set the create the SQL for the SelectCommand for a Gridview.

The problem I am having is that when I submit the page to perform the search, the first 2 dropdowns repopulate and set the selected index accordingly, but the 3rd dropdown does not retain its selected value. It does populate with the values, but the selected value does not get set.

The correct values are available for the SelectCommand which returns the correct values.

View 1 Replies

Web Forms :: Repeater Losing Data On Postback

Jul 3, 2010

Private Sub UpdateOffensiveStats()

Repeater losing data on postback

View 2 Replies

Javascript - Disabled Radio Button Losing Value After Postback

Feb 14, 2011

I have two radio buttons that are disabled with javascript when the page loads. RadioButton1 is checked by default. When I click the button to do a postback, the RadioButton1 is no longer checked.

Here's my code sample. The code behind is empty.

<asp:RadioButton ID="RadioButton1" runat="server" GroupName="group" Checked="true"/>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="group" />
<asp:Button ID="Button1" runat="server" Text="Button"></asp:Button>
<script type="text/javascript">
window.onload = function () {
var RadioButton1 = document.getElementById('<%= RadioButton1.ClientID %>');
var RadioButton2 = document.getElementById('<%= RadioButton2.ClientID %>');
RadioButton1.disabled = true;
RadioButton2.disabled = true;
};
</script>

View 4 Replies

Checkbox Losing Value On Postback Due To JavaScript / JQuery Array?

Feb 1, 2011

I have a simple asp:RadioButtonList within a form tag but for some reason it isn't keeping it's value on postback

Here's what I've got

[code]....

View 3 Replies

AJAX :: Losing Javascript Events On Async Postback?

Apr 27, 2010

I am creating a ASP.Net server control to manage locations. The control is a composite control containing several text-boxes, labels, and a link button. I use the AJAX Control Toolkit to provide a modal popup which contains a Bing map. All the Javascript is in its own file and used as an embedded web resource.

The link button is what opens the modal popup. It also needs to call a Javascript function that initializes the Bing map (onclick = "GetMap();"). There are instances when this server control is placed within an Update Panel (and there is no way to avoid this). When in an Update Panel the link button loses its onclick event. I understand that this is because during an async postback the portion of the DOM that defines the content of the Update Panel is thrown out and reinitialized, resulting in the event breaking. When the control is not in an Update Panel everything works as intended.

I have tried registering events on Page.Load and Page.Init, like so:

[Code]....

I have also tried flat out writing the function call to the page:

[Code]....

I have put breakpoints on the lines inside each delegate and they do not get hit. I am not aware of any special way to register events of a composite control's child control or the Page.Load/Page.Init events when being done inside a server control. Is there some special way to register these events? (Note: Both those code blocks above are in my CreateChildControls() method)

Below is the GetMap() Javascript function. As you can see it is pretty straight forward.

[Code]....

View 3 Replies

Forms Data Controls :: Losing Gridview Row Value On Postback?

Nov 3, 2010

i have a global field called hotelId. i then have this piece of code that gets a value from gridview row:

[Code]....

the local variable is assigned to my global one, which gets passed to my method along with other variables. while stepping through i can see the value is set, but when i hit the submit button variabl is passed to another method except my hoteId. it gets lost...

View 3 Replies

DropDownList Within Composite Control Is Losing Selected Value On Postback

Feb 23, 2010

I am building a composite server control that currently only has a TextBox and a DropDownList. Here is the code in all its foetal glory:

[Code]....

The control appears to work correctly across postbacks, that is until declarative values are set, e.g.:

<squee:Address runat="server" ID="a" Street="123 Fake St" State="VIC" />

After this, the text box continues to work correctly, but the _state member does not pick up the posted back values and instead just sticks to the declared value. I've checked the raw posted values in the Request object, and the new value for the list's UniqueID is there, but _state doesn't pick it up.

View 1 Replies

JQuery :: TextboxWaterMarkExtender And Datepicker - TextBox Losing Value On PostBack?

Feb 25, 2011

I have a textbox that uses TextboxWaterMarkExtender and jquery-ui's datepicker plugin.Upon postback, my textbox is losing the value selected from jquery datepicker.Below is the sample code to see the behavior. Is there anyway I can make my textbox to retain selected value on postback?One thing to note is, if I use jquery watermark plugin, it does postback the value. But for certain reasons, I think I plan to use AjaxControlToolkit.

[Code]....

View 2 Replies

Custom Server Controls :: Extending A Control And Losing Values On Postback?

Nov 24, 2010

I've created loads of user controls, but this is my first time dealing with extending a server control. The problem I'm getting is that the base control's data is not being persisted across postbacks in a Master/Content page.I'm actually trying to get this working using a Telerik control (for my sins), but the same issue happens with a standard Web TextBox control. Code:

[Code]....

Now, I've copied the way I handle the control state as I do it with user controls (ControlState), and it isn't working. Can someone point me in the right direction please? All the examples I find refer to creating user controls, not extending existing controls. Specifically why nothing is being persisted on post back.

View 7 Replies

Form Authentication Redirect Url?

May 10, 2010

I want to use custom redirect url in form authentication, means if authentication successfull then I want to redirect the user to a page depending the user type, if user is administrator then admin.aspx page and if user is customer then customer.aspx and if user is retailer then retail.aspx page.how can i do this ?

View 15 Replies

Response.Redirect In New Browser Window

Aug 31, 2010

protected void ddlPrint_Changed(object sender, EventArgs e)

View 4 Replies

Security - Forms Authentication Without Redirect?

Feb 2, 2010

I am using ASP.Net's forms authentication, but do not want the default behavior of redirecting to a login page when a restricted area is accessed. Instead I would like to invoke a javascript JQuery dialog for the login on the current page, preventing the content behind from loading.My only issue is that by default the forms authentication wants to redirect. Is there a handler that I can hook into, or some other option to prevent the redirect?

View 3 Replies

Security :: Authentication - Redirect URL For Different Roles?

Mar 10, 2010

I am currently having a spot of bother in something im trying to create. I want it so when a user who is in a certain role logs in they are directed to a certain page, and any other normal users are directed to another page.

I think i have this sorted via code but...

-The first time it will work, the 'admin' user will get directed to the appropriate page

-I then log out and log in as a normal user and get directed to the appropriate page

-then when i log out of that users account and back into the admin one i get directed to the normal users page instead.

-additional to this, I tried it on a different machine logging in as the admin user only to be redirected to the normal users page (is my session being stored somewhere?)

Ive traced through the problem and the user name and password being subbmitted are what they should be, yet it skips the true part of my IF statement for being in that role.

Here is my code I am using on the login form:

[Code]....

-When stepping through if seen it work and not work with the same values, I cant understand the logic of its inconsistency

the code i am using for the logout is (this is on my masterpage):

[Code]....

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved