httpcontext

accessing HttpContext.Request in a controller's constructor

ⅰ亾dé卋堺 提交于 2019-11-27 09:57:13
问题 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() { bool usuario = HttpContext.Request.IsAuthenticated; } } } The problem is that HttpContext is always null. Is there a solution to this? 回答1: The Controller is instantiated

Writing to ZipArchive using the HttpContext OutputStream

霸气de小男生 提交于 2019-11-27 07:57:55
I've been trying to get the "new" ZipArchive included in .NET 4.5 ( System.IO.Compression.ZipArchive ) to work in a ASP.NET site. But it seems like it doesn't like writing to the stream of HttpContext.Response.OutputStream . My following code example will throw System.NotSupportedException: Specified method is not supported as soon as a write is attempted on the stream. The CanWrite property on the stream returns true. If I exchange the OutputStream with a filestream, pointing to a local directory, it works. What gives? ZipArchive archive = new ZipArchive(HttpContext.Response.OutputStream,

HttpSelfHostServer and HttpContext.Current

冷暖自知 提交于 2019-11-27 07:28:21
I'm working on a self-hosted ASP.NET web api-application. Everything works fine, but now I'm struggling with HttpContext : I need to save session-informations from the client. But HttpContext.Current is always null. So it's obvious that my HttpSelfHostServer don't work with the static HttpContext-Class. The thing I don't understand is: why..? And I can't figure out a way to tell neither HtttpSelfHostServer nor HttpSelfHostConfiguration to work with HttpContext . Here's what I'm doing: Creating a HttpSelfHostConfiguration 1.1 Adding Service-Resolvers & Routes 1.2 Adding custom UserNamePassword

MVC5 Ninject binding and HttpContext

此生再无相见时 提交于 2019-11-27 07:22:07
问题 I am trying to set up a new project and I've added a new class MembershipService that requires the HttpContext to be passed in it's constructor. In a previous project I used the code private static void RegisterServices(IKernel kernel) { kernel.Bind<IMembershipService>() .To<MembershipService>() .InRequestScope() .WithConstructorArgument("context", HttpContext.Current); .... } However in the new project I'm using Ninject Modules, and after some searching on StackOverflow and Google, I've come

HttpContext.Current.User.Identity.Name is always string.Empty

百般思念 提交于 2019-11-27 07:16:39
Hi I use a custom MembershipProvider. I want to know the current username during an application scenario, but when I try accessing HttpContext.Current.User.Identity.Name it always returns string.Empty. if (Membership.ValidateUser(tbUsername.Text, tbPassword.Text)) { FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity.IsAuthenticated; //true string y = User.Identity.Name; //"" FormsAuthentication.RedirectFromLoginPage(tbUsername.Text, cbRememberMe.Checked); } Am I missing something? FormsAuthentication.SetAuthCookie(tbUsername.Text, true); bool x = User.Identity

Using an HTTPContext across threads

自作多情 提交于 2019-11-27 06:41:37
问题 User hits page spawn.aspx which then spawns a half-dozen threads, rendering pages all using ((System.Web.IHttpHandler)instance).ProcessRequest(reference to spawn's HTTPContext); Don't worry about the fact that ASP.Net is seemingly sending the user 7 responses for 1 request, that part is handled and only one response gets sent. The problem is, in a high-traffic enviroment (our Production enviroment) with many threads (quad-quads) we get an error: System.IndexOutOfRangeException at System

What is the meaning of thread-agility in ASP.Net?

余生颓废 提交于 2019-11-27 05:08:35
I am reading an article about HttpContext and CallContext and see thread-agility. What does it mean? It means that IIS is free to use more than one thread to handle a single request, although not in parallel. Basically, IIS tries to perform I/O operations asynchronously, thus freeing the calling thread for the duration of the operation. That thread is returned to the pool and can be used to handle other requests in the meantime. When the asynchronous I/O operation completes, control can be returned to a thread other than the one that originally handled the request (since that thread can be

HttpContext.Items with ASP.NET MVC

只愿长相守 提交于 2019-11-27 04:29:08
问题 I'm implimenting my own ApplicationContext class that uses the singleton pattern. I want to store my instance of it in HttpContext.Items, since it is accessible in all parts of the request. I've been reading about using HttpContext with ASP.NET MVC and one of the major pains is that it introduces testing complexity. I've tried doing research on the testability of HttpContext.Items, but all I can find is stuff on Session. One of the only things I've found is out of a sample chapter in the

HttpContext.Current.User.Identity.Name is Empty

爱⌒轻易说出口 提交于 2019-11-27 04:28:31
I have a Silverlight application (using MVC) and when i'm building in visual studio, using Visual Studio Development center, there's no problem, the HttpContext.Current.User.Identity.Name has a Value But when i'm using the same project with IIS 7.5 (i'm using Windows 7), HttpContext.Current.User.Identity.Name stays empty Anyone who can help? Or knows where i can find the settings from the visual studio Development center, so i can check what's wrong in IIS? I struggled with this problem the past few days. I suggest reading Scott Guthrie's blog post Recipe: Enabling Windows Authentication

Get current System.Web.UI.Page from HttpContext?

随声附和 提交于 2019-11-27 03:21:45
This is actually a two part question. First,does the HttpContext.Current correspond to the current System.UI.Page object? And the second question, which is probably related to the first, is why can't I use the following to see if the current page implements an interface: private IWebBase FindWebBase() { if (HttpContext.Current as IWebBase != null) { return (IWebBase)HttpContext.Current.; } throw new NotImplementedException("Crawling for IWebBase not implemented yet"); } The general context is that some controls need to know whether they are executing as a SharePoint webpart, or as part of an