httpcontext

accessing HttpContext.Request in a controller's constructor

I'm following this ASP.NET MVC tutorial from Microsoft: My code is slightly different, where I'm trying to access HttpContext.Request.IsAuthenticated in the controller's constructor. namespace SCE.Controllers.Application { public abstract class ApplicationController : Controller { public ApplicationController() ...

Accessing controller method from ResultExecutingContext in ASP.NET MVC site

I'm writing an attribute where I want to access a method on the class that the controller that has the attribute on one of its actions derives from. That's quite a mouthful, so let me explain: My controller derives from a class that has a method with the following signature: protected bool IsSearchEngine() (the base class itself derive...

How can I make HttpContext available to be used by my Unit Tests?

Hi, I want to write a unit test which tests the function of a class called UploadedFile. The problem I face is this class' static constructor uses HttpContext.Current property and because I am running my unit test from a class library I do not have an HttpContext at the testing time. Look at my static constructor: static UploadedFil...

How can I fake HttpContext for unit tests?

Hello, I need to fake HttpContext.Current.Application table to access it from my unit tests. I need to store my data somewhere. I thought that I can just pass instance of NameValueCollectionBase but as I descover this base type has no indexer so it's too complicated to use. So what about faking this part of HttpContext? Is it possib...

What is the most complete mocking framework for HttpContext

I'm looking for as comprehensive as possible of a mock replacement and wrapper for the ASP.NET HttpContext in my applications. A comprehensive mock replacement could potentially increase the testability of my ASP.NET web applications substantially, without necessitating migrating every application to more-testable frameworks such as MVC....

Can't find HttpContext in .NET 3.5 and Visual Studio 2008

I used code from here and I get the following error: Can't use HttpContext.Current.Server.MapPath() In Visual Studio 2008 does the ContextMenuEntry "Solve" help you when you have missing references? I already found out that HttpContext is not a member of System.Web in my IDE. According to Help > Info I am using .NET 3.5 SP1. How ...

HttpContext at Handler

For protect download files purposing I created http handler liket this: public void ProcessRequest(HttpContext context) { string user = HttpContext.Current.User.Identity.Name; FilePermissionHelper helper = new FilePermissionHelper(user); string path = context.Request.Form["file"]; bool canDownload = h...

Injecting HttpContext in Ninject 2

In my asp.net mvc application I'm using Ninject as a DI framework. My HttpAccountService is used by my controllers to get info from and to cookies. For this I need the HttpContext.Current in the HttpAccountService. As this is a dependency I injected it throught the constructor as such: kernel.Bind<IAccountService>() .To<HttpAccount...

Nullref on Session.Current in App_Code file

I have a class Session.cs in the App_Code directory that needs to extract some values from the session. I define the session with this: System.Web.SessionState.HttpSessionState session = HttpContext.Current.Session; but when I run the page I get a Null Reference Exception on session. The class (Session.cs) gets called from anot...

ASP.NET MVC - Unit testing, mocking HttpContext without using any mock framework

Since I'm having problem with unit testing RenderPartialViewToString() with Moq framework (http://stackoverflow.com/questions/3621961/asp-net-mvc-unit-testing-renderpartialviewtostring-with-moq-framework), I'm thinking about getting my controller directly, without using Moq for these particular test, however, how do I mocks (or set) the ...

Example of a simple ASP.NET MVC + NHibernate + Fluent with proper session handling?

I'm new to all of these technologies. I would like to see a simple (not over the top) example of how you would set up a project with these technologies. The most important being the proper NHibernate session handling (using HttpContext). Or we can build off of what I already have. I've seen several examples of one piece or another but n...

JSF application giving 404 for a sub-context

My JSF application works in my local tomcat for URL like http://localhost:8080/MyApp/admin, but not on the hosting server, the URL there is http://www.myapp.com/admin Do I need to do something with 'context.xml'/ put BocBase & AppBase. I got these things googling, but could not understand what exactly I have to do. Can anyone help me wit...

The specified LINQ expression contains references to queries that are associated with different contexts.

am getting this error on this code (this is an MVC project into which I am trying to integrate Entity Framework): List<string> consultantSchoolList = new List<string>(); // districts managed by consultant IQueryable<string> consultClients = rc.consultantDistrictsRepository.districtsForConsultant(userID); ...

To pass a value on runtime from HTTPContext as response

Hi, I am trying to pass a value from my HTTP handler module to the redirected response. I am planning to change the view with respect to this value. //HTTPmodule if (!authorizer.IsAuthorized(controller, action, context.User)) { context.Response.Redirect(AUTHORIZATION_FAILURE_URL); } AppAccess appAccess = appAuth.GetApplicationAccess...

Testing custom ModelBinder against HTTP context in ASP.NET MVC (1.0)

Hi, I'm trying to unit test a custom model binder - specifically, I want to see how it responds to various (possibly conflicting) values being submitted in the Request.Form and Request.QueryString collections - i.e. if I submit one value in the form and another in the querystring (yeah, yeah, I know, this is evil, but I want test covera...

Problem with TempData and Faked HttpContext using ASP.NET MVC

Hi Everyone, I am working with a faked HttpContext (code provided in the end) and probably I am missing something because I can't access TempData collection (forth line of SetFakeControllerContext method). Every time I try I get this error message: 'controller.TempData' threw an exception of type 'System.AccessViolationException' The ...

i want to know about HttpContext,request and response?

Hi all i want to know about HttpContext,request and response? can anyone give me the good tutorial link..(Basic things) thanks saj ...

What is the difference between HttpContext.Current.Application.Get([some enum]) and just enum?

I have: HttpContext.Current.Application.Get(KeyNames.EncodedKey).ToString() Where KeyNames is an enum. I can't use HttpContext. What should I check before I just use KeyNames.EncodedKey instead of HttpContext.Current.Application.Get(KeyNames.EncodedKey).ToString() ? (or is there another way?) Thanks. ...

How do i start and stop application state in ASP.NET

What seems to be happening is on a request some values I have retrieved are being stored in application state, but when I make changes to the values, the old values are still in application state for a while before finally going. I want a way to refresh the application state on each request.? ...

Unit Testing Web Services - HttpContext

I want to write unit tests for a web service. I create my test project, reference my web project (not service reference, assembly reference), then write some code to test the web services - they work fine. However, there are some services which make sure the user is logged in to the web application by using HttpContext.Current.User.Ident...