Tips on verifying "Session" in a .html file using `.NET`

Currently, I am attempting to verify the Session value from the .html page. Here is what I have done so far:

In ASPX I am setting the value in session and then redirecting to an html page.

Session["user_id_no"] = "1234";
Response.Redirect(url);  

Within HTML, I am initiating a REST GET method.

var check= $.ajax({
    url: "/loginCheck",
    type: 'GET',
    success: function (result) {
        return result;
    },
    async:false
});

Implementation of REST API and Method

[HttpGet]
[Route("loginCheck")]
public bool checkLoginStatus()
{
    SessionClass sc = new SessionClass();
    bool user_id_check = sc.check("user_id_no");       
    return user_id_check;
}

The Session Class has been created as follows:

public class SessionClass : System.Web.UI.Page
{
     public bool check(string sessionName)
     {
         if (Session[sessionName] == null)
             return false;
         return true;
     }
}

Unfortunately, I am encountering an exception.

HResult=-2147467259 Message=Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.

Even though my web.config contains the following:

<sessionState mode="InProc" timeout="30" />

I have also referred to some related questions

  1. How to access Session variables and set them in javascript?
  2. Getting session value in javascript
  3. 'Session' does not exist in the current context
  4. Session state can only be used when enableSessionState is set to true either in a configuration

Answer №1

Have you ever experimented with this code snippet?

import java.util.ArrayList;

public class ArrayListExample {
     public static void main(String[] args) {
         ArrayList<Integer> list = new ArrayList<>();
         list.add(5);
         list.add(10);
         System.out.println("List size: " + list.size());
     }
}

Answer №2

Make sure to set enableSessionState in your configuration file, as indicated by the exception message

<system.web>
      <pages enableSessionState="true" /> 
</system.web>

For additional details, refer to this helpful answer

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

increasing the size of an array in react javascript

componentWillMount(){ this.adjustOrder(); } componentDidMount(){} adjustOrder(){ var reorderedArray = []; this.state.reservation1.length = 9; for (var i = 0; i < this.state.reservation1.length; i++) { if(this.state.reservation1[i]){ r ...

Implementing event delegation as the default behavior on the document body

My problem began in IE8 when loading dynamic HTML pages containing script tags via AJAX (using magnificPopup.js). As a solution, I had to remove all the JavaScript code from these dynamically called pages and place them in a separate .js file. However, thi ...

simpleCart - Utilizing a modal window for easy input and sending the shopping cart data to PHP in a multidimensional array

Currently, I am working with the simpleCart JavaScript shopping cart, but I have encountered a minor issue. When a customer clicks "checkout," a modal pops up requiring them to enter their contact information. Upon submitting the form, an email is sent to ...

Challenges Ensuring Validation of Each Object in JSON Schema Using Postman

Despite its seemingly straightforward nature, I am encountering difficulties in fully validating JSON response data within Postman (Tiny Validator 4) when multiple objects are returned. During negative testing, I discovered that it only checks the first ob ...

Exploring Angular's Structural Directive for Parsing HTML Strings

I need help parsing an HTML string with a structural directive inside ng-template. Currently, it is being displayed as a string instead of the desired outcome where the structural directive iterates three times and shows three li elements. How can I achiev ...

Enable the feature for users to upload images to a specific folder within the Chrome extension without the need for

I need to implement a feature in my Chrome extension that allows users to upload images directly to a specific folder named "upload" without needing a submit button. <form action="/upload"> <input type="file" name="myimages" accept="image/*"> ...

Pattern matching: Identify text elements specifically within an HTML tag

I've been experimenting with a text highlighting script. Check out my initial attempt here. Here's the code snippet: http://jsfiddle.net/TPg9p/3/ However, I encountered a problem – it only works with simple strings and not those containing HT ...

Scripting issues detected in Safari and Microsoft Edge browsers

I recently finished developing an AngularJs Application that works flawlessly on Google Chrome and Mozilla Firefox. However, upon testing it on Safari and IE-11, I encountered errors in the console. One particular piece of code that causes issues is used ...

Conceal the <p> element when the user interacts with the internal href

After creating this document using JQuery, whenever the user clicks on different internal links, a div with id = "change" is loaded which effectively "erases" the content. My challenge at the moment is that while images are successfully deleted, text rema ...

Verifying Username with AJAX and JSON Technology

In a PHP file, I have stored usernames in JSON format. [ {"korisnicko_ime":"darbranis"}, {"korisnicko_ime":"markrc"}, {"korisnicko_ime":"leoluk"}, {"korisnicko_ime":"borbau"}, {"korisnicko_ime":"ivavad"}, {"korisnicko_ime":"andtikv ...

Acquiring exclusive files from Laravel 8 storage directory using JavaScript

I find myself in a specific situation: Working with a Laravel 8 application. My users upload STL files, which are stored in the storage/app/users/{userid} directory. These STL files are private and not accessible to everyone as they are not located in the ...

Experimenting with jQuery's .hide() and .show() functions with an alert message confirming that the div is not

Below is some simple code to demonstrate an issue: $('.myDiv').click(function() { $('.anotherDiv').hide(); alert('pause the ui'); $('.anotherDiv').show(); }); After clicking on the .myDiv element, the ...

The function "toggleHeightAndOpacity" cannot be accessed on this object because it is not defined

I'm attempting to invoke a variable function name, a task I have successfully accomplished many times in the past using code similar to that found here. <script type="text/javascript"> $.fn.toggleHeightAndOpacity = function(show) { ...

Display geographic data using d3 with geoJSON

I am struggling to render a geoJSON file using d3 because I am having trouble targeting the correct features for projection. Instead of working with the typical us.json file used in many d3 examples, my current map focuses on United States "Commuting Zone ...

PayPal Integration with React for Seamless Checkout Experience

I established a small and uncomplicated online store featuring a PayPal checkout system, and it is functioning adequately. Now, I am looking to include detailed information about the purchased products in the transaction history of my PayPal account. This ...

Ways to transmit the appropriate model

Using AJAX, I am sending a model to the server via a POST request. I have defined a model and a controller method for processing it. public class TestDto: BaseDto { [Required] public ProductGalleryDto GalleryProduct { get; set; } public int ...

Imitate a mouse click on a hyperlink using a Chrome extension

I am currently developing a Chrome extension and my main goal is to automate the process of clicking on links that lead to the next page. I have implemented jQuery.noConflict(); in my code, however I keep encountering an error in the Chrome console -jque ...

Employing Isotope/jQuery for organizing posts on Tumblr in columns with the ability to infinitely scroll

Alright so, here we have the classic dilemma where scripts are running before images load. And to make matters more complicated, on Tumblr, there's no way to access image dimensions before they're loaded into the DOM... $('#thumbnails&apos ...

Codeigniter is missing the Ajax call implementation

<script type="text/javascript" language='javascript'> $('#view_comment').submit(function() { alert("msg"); var sec={'post_id_for_view_comment' : $("#post_id_for_view_comment").val()} $.ajax ...

Concealing the URL Once Links are Accessed

I have a Movie / TV Shows Streaming website and recently I've noticed visitors from other similar sites are coming to my site and copying my links. Is there a way to hide the links in the address bar to make it more difficult for them to access my con ...