httpcontext

Get application path without using httpcontext. (asp.net)

How to do it? I don't want to use this: HttpContext.Current.Server.MapPath Is there a similar function that I can call without requiring a httpcontext? For example if a start a thread doing some stuff i cant use the httpcontext, but i still need to get the path of the app. And no i can't pass the context as an argument or read it fr...

HttpContext.Current NullReferenceException in Static Method

I have a static class with serveral static methods. In these methods, I'm trying to access the current thread's context using HttpContext.Current. For example: var userName = HttpContext.Current.User.Identity.Name; However, when I do that, I receive a NullReferenceException, the infamous "Object reference not set to an instance of an ...

StrongNameKeyPair problem when attempting to use MoQ

Hi, I'm trying to create a mock HttpContextBase for unit test. var fakePrinciple = new GenericPrincipal( new GenericIdentity(userId), rolesList.ToArray()); var mockHttpContext = new Mock<HttpContextBase>(); mockHttpContext.Setup(t => t.User).Returns(fakePrinciple); HttpContextBase mockedContext = mock...

Use Session state within pLinq queries

Hi, I have a fairly simple Linq query (simplified code): dim x = From Product In lstProductList.AsParallel Order By Product.Price.GrossPrice Descending Select Product Product is a class. Product.Price is a child class and GrossPrice is one of its properties. In order to work out the price I need to use Session("exchange_rate...

Frame Redirect in C#

I would like to execute a frame redirect in C# from my managed module for the IIS 7. When I call context.Response.Redirect(@"http://www.myRedirect.org");the correct page is shown but also the address is shown in the browser. And that is exactly what I do not want. So I want something like: private void OnBeginRequest(object sender, Even...

Where to use Controller.HttpContext

Hi, In my base controller's constructor I am calling an extension method that checks for specific cookies on the client. Currently I am using System.Web.HttpContext.Current to get the current context. However, I am lead to believe that I should be using Controller.HttpContext since it is more testable and contains additional informati...

webpart context.session is null

I've been using the session array to store a state variable for my webpart... so I have a property like this: public INode RootNode { get { return this.Context.Session["RootNode"] as INode; } set { this.Context.Session["RootNode"] = value as object; } } ...

HttpContext User value changing on its own?

Hi everyone, I'm working on an ASP.Net 2.0 application and am having a strange issue involving the HttpContext User. It appears to be changing on its own when I go to a particular page/directory. All of our pages inherit from a base page. In that base page's Page_Load() method we run an authorization check to see if the user can see ...

Is Context.Items user scope or application scope?

Hi every one! I want to use Context.Items to store some info of a User Control like: Context.Items["Data"] = 5; I want to know, Is Context.Items is for each request or it is global for the application? ...

Storing data in HttpContext.Current.Items vs ViewData

When is it appropriate to store data in HttpContext.Current.Items[...] vs storing data in ViewData[...]? I'm trying to figure out the best practices for storing data in this collection and I'm not sure if it's safe to store user-specific data in HttpContext.Current.Items. One use-case is passing down user credits from a base controller...

How to get .NET HttpContext for isolated code block

Hi, In .NET is it possible to get the HttpContext of the current page from within an external class? So, for example in my page test1.aspx codebehind I've got: Dim blah As New FeedWriter() blah.Run() But inside FeedWriter.vb, can I get the HttpContext of test1.aspx? Or would I have to pass it in to Run()? (I'm unwilling to d...

Missing HttpContext

Hi, I've got a project which as a reference added to System.Web. However, it can't seem to pick up HttpContext. Doing this: Imports System.Web _ApplicationBase = HttpContext.Current() Tells me that HttpContext is not declared. If you look at the methods and properties inside System.Web there are hardly any showing: only AspHostingPe...

HttpContext.Current.Request.UserHostName is empty when called from a class

I have various web pages that need to build up a URL to display or place it in an emitted email message. The code I inherited had this value for the name of the webserver in a Public Const in a Public Class called FixedConstants. For example: Public Const cdServerName As String = "WEBSERVERNAME" Trying to improve on this, I wrote this...

IIS: No Session being handed out, but only in production

I've reproduced this in a simple project - details below. It's a WCF service in ASP.NET compatibility mode. What I'm seeing is that when run on the dev machine (Win7), a HTTP session id is available inside the service operation (HttpContext.Current.Session is non-null). But when deployed to the server (Win2k8R2), I get "No session". On b...

UrlHelper and ViewContext inside an Authorization Attribute

I have a scenario that I haven't been able to solve: I'm toying around with creating my own custom authorization attribute for mvc. The main bit of functionality I would like to add is to have the ability to change where the user gets redirected if they are not in a certain role. I don't mind that the system sends them back to the login...

Testing ASMX webservice using NUnit and transferring session state

I have a NUnit test class that starts an ASP.NET web service (using Microsoft.VisualStudio.WebHost.Server) which runs on http://localhost:1070 The problem I am having is that I want to create a session state within the NUnit test that is accessible by the ASP.NET web service on localhost:1070. I have done the following, and the session ...

Inheriting LINQ-to-SQL data context from base controller

My base controller class, BaseController, is inherited by public-facing controllers to access a shared data context between requests with LINQ-to-SQL. Am I accessing my data context in an efficient and safe way by storing it in HttpContext.Current.Items for each HTTP request? DataContextHelper class internal static class DataContext...

Storing Requested URL in Global.asax without Session State in ASP.NET

I have a complex URL rewriting scheme which breaks the built in Forms Authentication ReturnUrl mechanism. I would like to grab the requested URL for later redirection away from my login.aspx. I can get this URL in Application_BeginRequest via HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath. However, Session state is not a...

HTTPContext issues (ASP.NET MVC2)

Hey guys, this is a weird one! I have a site that I have deployed in 3 places. 1. My local machine. 2. Dev Server 3.QA Server. My project runs on my machine and the dev server. On the QA server, it runs, but the HTTPContext object is blank (not pulling from AD, etc). All 3 machines live on the domain. The Dev Server and QA Server are ...

Where is origin of HttpContext.Current.Request.Url.Host?

Why does HttpContext.Current.Request.Url.Host return a different URL than the URL used in the Web browser? For example, when entering "www.someurl.com" in the browser, the HttpContext.Current.Request.Url.Host variable is equal to "www.someotherurl.com". ...