Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: Quick Reference - ASP.NET

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: Tue, Aug 23, 2011, 9:07 AM


General

ItemCode
Current HTTP Request objectHttpContext.Current.Request
Session IDstring sessionId = HttpContext.Current.Session.SessionID;
Maintaining scroll position on postbackIn the <%@ Page %> directive, set the MaintainScrollPositionOnPostback property to true
Disabling caching of a page.In the Page_Load event handler: Response.Cache.SetCacheability(HttpCacheability.NoCache)

Client Information

ItemCode
IP addressRequest.UserHostAddress
Computer Nameusing System.Net;

string remoteHost = Request.ServerVariables["REMOTE_HOST"];
IPHostEntry client = Dns.GetHostEntry(remoteHost);
string clientName = client.HostName;
uxClientNameLabel.Text = clientName;
User Nameusing System.Net;
string remoteUser = Request.ServerVariables["REMOTE_USER"];

or string remoteUser = Request.ServerVariables["AUTH_USER"];
or System.Web.HttpContext.Current.User.Identity

URL of Application Root

The following method will return, for example, http://localhost:2297/Version 1.0/. This is the root directory of the web application: the current page's URL, stripped of the path, filename, and any query string. For more information on using this function with CSS, JS, and XSL files, go here.

{copytext|AppRoot}
Public Shared ReadOnly Property ApplicationRootUrl() As String
    Get
        Dim r As HttpRequest = HttpContext.Current.Request
        Dim result As String = r.Url.Scheme
        result &= System.Uri.SchemeDelimiter
        result &= r.Url.Authority
        result &= r.ApplicationPath
        result &= "/"
        Return result
    End Get
End Property

public static string AppRootUrl
{
    get
    {
        var r = HttpContext.Current.Request;
        var result = r.Url.Scheme;
        result += Uri.SchemeDelimiter;
        result += r.Url.Authority;
        result += r.ApplicationPath;
        result += "/";
        return result;
    }
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.