[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Read cookies using ASP.NET written using JSP

Posted on 2006-03-22
6
Medium Priority
?
562 Views
Last Modified: 2008-03-06
I have a situation where I need to pass an initial value from JSP to ASP.  I'm already writing further values to a database.  I've seen several solutions to this JSP to ASP issue, and most mention using cookies, but never with an example.  I'm currently not able to read a cookie on the ASP.NET side that was written on the JSP side.  I am using tomcat running under IIS (ISAPI).  Thank you in advance for your help!!!
0
Comment
Question by:ByronHall
5 Comments
 
LVL 6

Expert Comment

by:enwhysee
ID: 16267717
Since cookies are stored on the client (in the browser), the server-side language (JSP or ASP) shouldn't matter :)     The actual cookie gets set using JavaScript. So, your ASP/JSP/etc. code would need to generate the appropriate JavaScript to accomplish the task.

Here is an article on how to get and set cookies, if it helps: http://www.htmlgoodies.com/beyond/javascript/article.php/3470821

Additionally there are two issues:
If you your jsp site and the asp site are on different domains, they won't be able to read each other's cookies for security reasons.

Have you considered passing values using a GET or a POST instead?
Using a GET, you'd pass them like  http://site/yourasp.aspx?name=John&age=30&id=1234 sort of thing.
Using a POST, you'd need to construct a <form> and then submit it using JavaScript.

for example

<form action="youraspx.aspx" id="myForm">
    <input type="hidden" name="name" value="John">
    <input type="hidden" name="age" value="30">
    <input type="hidden" name="id" value="1234">
</form>
<script language="JavaScript">
   document.getElementById('myForm').submit();
</script>


The GET is the easiest to accomplish, but the value you're passing will be seen in the address bar. If it is something like a password/confidential information, or something that could be pretty long (i.e. a couple of hundred characters), then you'd need to use the POST or cookies.

Hope that helps!

0
 
LVL 4

Expert Comment

by:barnesd1
ID: 16270666
Try adding an expiry date to you cookies eg
Response.Cookies("TestCookie").expire = date() + 7
0
 

Author Comment

by:ByronHall
ID: 16271034
barnesd1....Which side (JSP or ASP) are you suggesting I add that?  That looks like ASP code but I'm setting the cookie on the JSP side.

enwhysee....I tried what you suggested about the cookie, but could not get it to read on the ASP side.  The JSP and ASP pages are in the same domain; In my current case "localhost".  In addition, as JavaScript is many times disabled in my environment (plus I need the cookie values in ASP not JavaScript) I can't rely on JavaScript.  Also, the demo in the article you provided didn't work.  I have considered both of the GET and POST methods, and I know they will work.  However, I need to provide justification to my decision of which method (GET/POST/Cookie) I use.  I basicly need to know if I can use cookies (and how) as I have described.
0
 

Author Comment

by:ByronHall
ID: 16271320
I have solved this issue.  JSP was setting the path attribute of the cookie automatically to the path of the jsp file.  And, since the ASP page is in a different path it couldn't read the cookie.  I coded the path of the cookie to match the ASP page (or just "/" would work) and I can now read the cookie.

Thanks for your help.
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16629024
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question