Cookies and Redirecting
|
مشرف
تاريخ التسجيل: 2006-02-19 مشاركات: 2655
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثالثة
|
Hello all,
I have a login page, this page sends a cookie to the client when he/she logs in successfully, on the same process the page will redirect the client to the page he/she was viewing, the problem is the cookie is not sent to the client on redirection, how can we solve it?
يجب علينا في ظل هذه الظروف الصعبة, أن نقف جميعا ً, صفا ً واحدا ً ...... أمام الفرن
I am a Muslim
|
| |
دخول أو تسجيل لإرسال التعليقات | قراءة: 319 |
|
مدير
تاريخ التسجيل: 2005-07-15 مشاركات: 3149
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الخامسة الاختصاص: هندسة برمجيات
|
I'm not a web dev but AFAIK you need to redirect from the client side (using javascript for instance) cause I've seen a lot of web sites work this way.
That means you need to send a response page to login process this page has a client-side code that will redirect the user to the required destination.
HTH
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
مشرف
تاريخ التسجيل: 2006-02-19 مشاركات: 2655
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثالثة
|
Thank you foaad, never thought of it 
It might help, I'll reply when I try it.
يجب علينا في ظل هذه الظروف الصعبة, أن نقف جميعا ً, صفا ً واحدا ً ...... أمام الفرن
I am a Muslim
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
عضو فعال
تاريخ التسجيل: 2007-09-17 مشاركات: 829
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثانية
|
أنا ساويتها من قبل بنفس الطريقة اللي قلك عليها فؤاد " باستخدام الجافا سكريبت " على الحالتين بتسجيل الدخول و بتسجيل الخروج بس بتم توجيه المستخدم للصفحة الرئيسية
| IF YOU LOST THE WAY DON'T GIVE UP AND GO BACK ,try again...YOU WILL ALWAYS FIND THE SOLUTION AT THE STARTING POINT |
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
مشرف
تاريخ التسجيل: 2006-02-19 مشاركات: 2655
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثالثة
|
So let me try to figure it out: 1. The user directed from a page that requires authentication to the login page. 2. The user logs in successfully. 3. I send the user the cookie with the response. 4. The JavaScript will redirect the user to some page. How am I gonna activate the JavaScript code? What will the JavaScript code look like? I know some little tiny winy JavaScript
يجب علينا في ظل هذه الظروف الصعبة, أن نقف جميعا ً, صفا ً واحدا ً ...... أمام الفرن
I am a Muslim
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
عضو فعال
تاريخ التسجيل: 2007-09-17 مشاركات: 829
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثانية
|
first why you dont send the cookie also form java script code ??? 1. user inter correct information in log in page 2. you direct to page that ensure that the data is correct 3.if the data is correct you " echo " a page that contain the code of java script and the redirection information
| IF YOU LOST THE WAY DON'T GIVE UP AND GO BACK ,try again...YOU WILL ALWAYS FIND THE SOLUTION AT THE STARTING POINT |
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
مشرف
تاريخ التسجيل: 2006-02-19 مشاركات: 2655
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثالثة
|
كتب BlackSigma: first why you dont send the cookie also form java script code ???
'cuz some of the the cookie's information is retrieved from the database on the serve, and the others are hard-coded in C# code on the server.
Anyway thank you BlackSigma.
I'm thinking of another way,
1. The user enters the information.
2. The page checks the validity of the information, if valid, sends the cookie without redirection.
3. On page load event, if the request has the cookie, redirect to the page he/she was viewing.
It might work too.
يجب علينا في ظل هذه الظروف الصعبة, أن نقف جميعا ً, صفا ً واحدا ً ...... أمام الفرن
I am a Muslim
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
مشرف
تاريخ التسجيل: 2006-02-19 مشاركات: 2655
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثالثة
|
Solved  This is what I did: 1. The user enters the information. 2. The page checks the validity of the information, if valid, sends the cookie without redirection, the page will also "echo" a JavaScript function to redirect to the page he/she was viewing, and also will set the time out for the function call to 5 seconds for instance. 3. The user will see a message "Please wait while you'll be redirected to where you were." Thank you foaad, thank you BlackSigma, hope to reply to you in celebrations  BTW "echo" in ASP .NET is called "Response.Write"
يجب علينا في ظل هذه الظروف الصعبة, أن نقف جميعا ً, صفا ً واحدا ً ...... أمام الفرن
I am a Muslim
|
| |
دخول أو تسجيل لإرسال التعليقات |
تاريخ التسجيل: 2006-02-08 مشاركات: 101
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: ماجستير الاختصاص: ذكاء صنعي
|
كتب mpcabd: Solved  This is what I did: 1. The user enters the information. 2. The page checks the validity of the information, if valid, sends the cookie without redirection, the page will also "echo" a JavaScript function to redirect to the page he/she was viewing, and also will set the time out for the function call to 5 seconds for instance. 3. The user will see a message "Please wait while you'll be redirected to where you were." Thank you foaad, thank you BlackSigma, hope to reply to you in celebrations  BTW "echo" in ASP .NET is called "Response.Write"
I have had this very problem lots of times and the only solution was to use javascript
but This will raise another problem: what if the browser doesn't support javascript
I mean could we figure out the actual reason behind this problem, taking into considration that it happens in both asp .net and php
Is it a kind of http header conflict?
since cookies are set by using set-cookie header and redirection is preformed by "Location" header
Any idea?
اعمل لدنياك كأنك تعيش أبدا, واعمل لآخرتك كأنك تموت غدا
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
مشرف
تاريخ التسجيل: 2006-10-12 مشاركات: 1714
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الرابعة الاختصاص: هندسة برمجيات
|
I Have Read Somewhere That Any Web Page is composed at the end of Three Element : HTML, CSS, Java Script. (IMO CSS is not That Important )
New look, new work, new laptop, new room, new challenges,and many new stuff It's not my birthday it's my revolution
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
عضو فعال
تاريخ التسجيل: 2006-12-10 مشاركات: 1473
الجامعة: الافتراضية الكلية: تكنولوجيا المعلومات المرحلة: متخرج
|
AIK,a redirecting is automatically followed, so you don't have to think about it. Cookies are handled automatically as well, but just in a very primitive way (every cookie is sent back to the server, regardless of it's PATH or timeout).
Anyway you can check:
Redirection Cookie using JavaScript.
|
| |
دخول أو تسجيل لإرسال التعليقات |
تاريخ التسجيل: 2006-02-08 مشاركات: 101
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: ماجستير الاختصاص: ذكاء صنعي
|
It seems like a browser problem when the browser requests a web page usually it gets the response starting with: HTTP/1.1 200 OK but when the page is redirected the response will start with HTTP/1.1 300 Redirected It seems when the browsers sees this thing it completely ignores the rest of the header including the part responsible for cookies Could you please (the founder of this topic) try to replace:
Response.Redirect("somewhere.aspx" ) With:
Response.Headers.Add("Location","somewhere.aspx" );
اعمل لدنياك كأنك تعيش أبدا, واعمل لآخرتك كأنك تموت غدا
|
| |
دخول أو تسجيل لإرسال التعليقات |
|
مشرف
تاريخ التسجيل: 2006-02-19 مشاركات: 2655
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: السنة الثالثة
|
I tried what you said Ammar, nothing worked of the following:
Response.AppendHeader("Location", url);
Response.AddHeader("Location", url);
Response.RedirectLocation = url;
Response.AppendHeader("Location", url); Response.Flush();
Response.AddHeader("Location", url); Response.Flush();
Response.RedirectLocation = url; Response.Flush();
The cookie is sent but no redirection happened, I guess we should stay on JavaScript for now.
And for browsers that don't support JavaScript, I remember that all the websites tell you:
"Please wait while you'll be redirected to some page, if your browser doesn't support auto-redirection you can follow this link."
يجب علينا في ظل هذه الظروف الصعبة, أن نقف جميعا ً, صفا ً واحدا ً ...... أمام الفرن
I am a Muslim
|
| |
دخول أو تسجيل لإرسال التعليقات |
تاريخ التسجيل: 2006-02-08 مشاركات: 101
الجامعة: دمشق الكلية: الهندسة المعلوماتية المرحلة: ماجستير الاختصاص: ذكاء صنعي
|
كتب mpcabd: I tried what you said Ammar, nothing worked of the following:
Response.AppendHeader("Location", url);
Response.AddHeader("Location", url);
Response.RedirectLocation = url;
Response.AppendHeader("Location", url); Response.Flush();
Response.AddHeader("Location", url); Response.Flush();
Response.RedirectLocation = url; Response.Flush();
The cookie is sent but no redirection happened, I guess we should stay on JavaScript for now.
And for browsers that don't support JavaScript, I remember that all the websites tell you:
"Please wait while you'll be redirected to some page, if your browser doesn't support auto-redirection you can follow this link."
I just wanted to figure out why
but it seems it needs more efforts
اعمل لدنياك كأنك تعيش أبدا, واعمل لآخرتك كأنك تموت غدا
|
| |
دخول أو تسجيل لإرسال التعليقات |
|