Click here to Skip to main content
15,904,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In an interview I was asked a question about ASP.NET that how can we share data among multiple users without using application variable and database logic?

Thanks
Posted
Updated 20-Feb-15 12:08pm
v2
Comments
Maciej Los 20-Feb-15 12:12pm    
Does your browser is broken?
touseef4pk 20-Feb-15 12:13pm    
Yes.. trying to fix it :D
Maciej Los 20-Feb-15 12:27pm    
https://msdn.microsoft.com/en-us/library/ms178594%28v=vs.140%29.aspx
touseef4pk 20-Feb-15 15:03pm    
I think u didn't read my question carefully. I said I just don't want to use Application variables

1 solution

There are quite a multiple options, some are defined in the actual web development framework (HTML and JavaScript APIs) and some are ASP.NET's APIs. Since he was not interested in the Application variables, it means that he was interested in asking you about the client-side APIs, JavaScript way of sharing the data or HTML way of sharing the data.

In HTML, you can send the data from one page to another page, using the action attribute of the form. You can assign the URL of the second page in the action attribute and then you can send it to the next page. The data in the form, can be then easily accessible on that page too. For example, the following HTML markup,

HTML
<form method="post" action="~/second_page.html">
   <!-- Empty form -->
</form>


That form, upon submission, would be redirected to the second_page.html and there you can use the data filled in this page. You would be required to use some server side language; ASP.NET or some other so make sure you're using correct file format.

Another way of doing the same thing is using the JavaScript's APIs. localStorage, sessionStorage are two ways that you can store the data from one page, and then use it on different pages (across the same application). You can learn more on Storage APIs from MDN[^]. You can store any type of data, and then extract the value on other pages.

For example, this is an example code for this scenario from MDN.

JavaScript
// Save data to the current session's store
sessionStorage.setItem("username", "John");

// Access some stored data
alert( "username = " + sessionStorage.getItem("username"));


Anyhow, I have written an article that would let you understand the processes and methods that you can use to share the data across multiple web pages on your website. You can read that article here: How to share data among different web pages using ASP.NET[^]. Remember, I have also mentioned there, and I will say it here too. Do not store sensitive data such as password in client-side APIs. User can easily manipulate them. Always store such values on the server-side; Application variables or more better in a database.
 
Share this answer
 
Comments
touseef4pk 22-Feb-15 14:06pm    
thanks actually I was interested in solution for multiple users across the application while your solution is perfect for accessing data across multiple pages for a single user
Afzaal Ahmad Zeeshan 22-Feb-15 14:48pm    
Then use the database to share the data for multiple users across the application.
touseef4pk 23-Feb-15 13:30pm    
We can't use database as well. It is mentioned in the question I posted :). However, I got the answer we can use http.context.cache.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900