.Net authentication using Windows credentials

As I work on developing a website utilizing ASP.net and C#, one of my requirements is to utilize windows authentication for user login.

Currently, I am experimenting with storing the authenticated user's name in a session in order to access it later within the website.

Could someone provide guidance on how to successfully achieve this?

Answer №1

Set the session variable for the username like this:
Session["User"] = username;

To retrieve the username, use the following code:

string user = (string)Session["User"];

Alternatively, you can access the session variable in a JavaScript script like so:

<script type="text/javascript>
var currentUserName = '<%= Session["User"].ToString() %>';
</script>

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

Combining two containers in CSS

I am currently working on building a website design, and I have a menu positioned on the right side of the layout. Below is the code for the menu along with an explanation. #rightmenu { border-top: 1px solid #000000; border-right: 1px solid #00000 ...

I am having issues with the accuracy of my JavaScript number validation function

function CheckIfNumeric() { var quantity = jQuery("#txtShippedQuantity").val(); quantity = quantity.toString(); for (i = 0; i < quantity.length; i++) { var character = quantity.charAt(i); if (isNaN(character)) { ...

Having trouble overriding the Slick carousel style in Angular 6?

Currently, I am utilizing Slick and jQuery for a carousel on my website. There seems to be an issue with the overriding style for the slick dots set in the component. Despite specifying the style in the component's CSS, the slick dots do not reflect t ...

Choosing a root element in a hierarchy without affecting the chosen style of a child

I am working on a MUI TreeView component that includes Categories as parents and Articles as children. Whenever I select a child item, it gets styled with a "selected" status. However, when I click on a parent item, the previously selected child loses its ...

Exploring the functionality of CRUD operations through selenium webdriver testing

My goal is to run tests on a web application that involve creating, editing, and deleting entries from a database. The issue I'm facing is that the tests are interdependent, meaning I have to create an entry before editing or deleting it. Is there a r ...

The mvc button seems to be unresponsive when clicked

After successfully resolving the issue I previously posted about here, I have encountered a new problem. Despite achieving the desired result, when I try to save, nothing happens. No error messages, no postback, and no data gets saved to the database. The ...

Creating an Outlook email template without relying on margins, padding, or positioning

I've been tasked with creating a template for Microsoft Outlook email that involves adding a dynamic image and text from the server onto an existing static background image. I attempted to design it using both divs and tables, utilizing inline CSS and ...

Tips on resetting the position of a div after filtering out N other divs

Check out this code snippet. HTML Code: X.html <input type="text" id="search-criteria"/> <input type="button" id="search" value="search"/> <div class="col-sm-3"> <div class="misc"> <div class="box box-info"> ...

Using class binding for both ternary and non-ternary attributes

Suppose we have a tag that utilizes a ternary operator to apply alignment: <td :class="alignment ? ('u-' + alignment) : null" > This functions as intended since the pre-defined alignment classes are in place, now if we want to ...

Exploring the principles of updating a table in SQL Server

I am working on an asp.net web application where users are able to update a table in the database. I am seeking guidance on the appropriate method to achieve this. The image provided illustrates that the red shaded area contains data that is common and doe ...

The content inside the HTML body doesn't fully encompass the dimensions of the mobile screen

I am working on making my application flexible by using 100vw width and 100vh height for the components. Everything displays perfectly in any resolution on a computer browser, but when viewed on a mobile device, an empty background is drawn below the bod ...

Verifying identities across a variety of subdomains (with some exclusions)

Currently, my website is hosted on www.domain.com, where users can log in and have their credentials stored in a cookie. Sometimes, these users access handlers located on different servers under a separate subdomain, handlers.domain.com. I cannot use wil ...

Is it possible to append a series of query strings to uribuilder, either in list or array format?

Currently, I am using UriBuilder to construct a URL for an API endpoint and adding query strings to it. Here is an example of how I achieve this: private async Task<string> CallAPI(string url, string queryString) { string s = "ht ...

Capitalize the host name from both the current HTTP request in the HttpContext object and the

Curious inquiry, I must admit, but nonetheless, is it possible for HttpContext.Current.Request.Url.Host or window.location.host to return a value in uppercase? Would it be advisable to utilize .toLowerCase and .ToLower methods to ensure everything goes s ...

Exploring the Differences Between Nth-CSS and Jquery

What are the advantages of using the nth function in CSS instead of applying it through jQuery, especially considering its compatibility with IE? Is it better to simply use jQuery from the start and avoid using it in a stylesheet altogether? Hopefully thi ...

Strange circle border appearance in Android / Chrome device

Having an issue with my code on a Samsung Galaxy S5 in Chrome 54.0.2840.85, Android 6.01. You can view the problematic codepen here: http://codepen.io/johnsonjpj/pen/jVpreB The border displays correctly on Firefox and iPhones, but not on my device. Trou ...

Experiencing discrepancies in pixel height while conducting tests using Nightwatch

Let me start by sharing some details about my machine setup: Operating System: CentOS 7 Graphics Drivers: kmod-nvidia (dedicated GPU) I am currently testing a webpage using Nightwatch, and one of the requirements is to ensure that a background image&apo ...

Customize your Bootstrap 4 card: change the header content, keep the body fixed

My current project involves the use of a bootstrap 4 card element: <div class="card" style="height:"500px;width:100px"> <div class="card-body"> <div class="top-portion"> This section can b ...

How to achieve a text border effect using inner glow technique

Can someone help me recreate this unique text design? The font used is Gill Sans MT and the text color is a shade of purple although it may be hard to discern. https://i.sstatic.net/HGrB8.png I have been struggling to achieve the vibrant thick border and ...

Two collapsible menus featured in the navigation bar

My navbar is displaying two collapse menus, but when one is active and I open the second one, the collapsed content from the second menu gets added to the end of the first one's content. How can I close the other menu when opening the second one? h ...