Redirecting after setting a normal session object?

Last night i almost gone  crazy, because no redirection occured, when i pressed on specific button. Only thing i have done, was, settings the session for the first time. Since searching for an answer to solve this solution, angry like hell, i found out, i never learned, how Response.Redirect really works (this ). After scratching and studying on a white paper and reading ASP.NET forums ( i decited to put it all together), it is really simple mechanism. When response.redirect start's,  add special header to the object and send request to the server. After that Response.End is called and current thread is aborted, page execution is ended.

my code:

Session["SomeKey"] = "something"; //add something to the code

Response.Redirect("~/testpage.aspx") 

Well, here is the catch. When session is first time created, server creates a special cookie, where session token is created. On all further request, server looks into this cookie, and find appropiate session token ( if you are using cookieless session, then session is saved in a url - for more info, read this ). Now, he knows, which session to call. But if you do upper situation, it maybe wont work. Why? Because Response.Redirect stops execution of a page, the session token is lost in translation Stick out tongue Best way to get things really working is to use

Response.Redirect("~/testpage.aspx", false);

or use another type of redirect ( like Server.Transfer ... ). Differences founded here.  

 

Avtor: bojanv, objavljeno na portalu SloDug.si (Arhiv)

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

HedaWhece
HedaWhece - petek, 08. november 2024

<a href=https://fastpriligy.top/>priligy equivalent</a> 37 Although intuitively the immunosuppressive effects of mTOR might be expected to outweigh any beneficial effect on limiting tumor cell growth in patients with malignancy, this seems not to be the case and a number of new sirolimus derivatives have been developed specifically for use as antitumor agents, including temsirolimus CC1 779, a sirolimus derivative formulated for intravenous administration