httpcontext

asp.net mvc compress stream and remove whitespace

你说的曾经没有我的故事 提交于 2019-12-03 05:20:13
问题 So I am compressing my output stream via an action filter: var response = filterContext.HttpContext.Response; response.Filter = new DeflateStream(response.Filter), CompressionMode.Compress); Which works great. Now, I would also like to remove the excess whitespace present. I found Mads Kristensen's http module http://madskristensen.net/post/A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx. public class WhitespaceFilter : Stream { // using Mads Kristensen httpModule // http://madskristensen

ASP.NET MVC: HTTPContext and Dependency Injection

佐手、 提交于 2019-12-03 03:54:39
问题 Currently I have an ActionFilter that gets the current users name from HttpContext and passes it into the action which uses it on a service method. eg: Service.DoSomething(userName); I now have a reason to do this not at the action level but the controller constructor level. Currently I'm using structure map to create controllers and inject the service. I'm looking at something like: public interface IUserProvider { string UserName { get; } } public class HttpContextUserProvider :

Unit Testing Web Services - HttpContext

不问归期 提交于 2019-12-03 02:50:12
问题 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.Identity.IsAuthenticated . In the context of the tests, there is no such thing as HttpContext, so the tests always fail. How should these kinds of web services be

Get/Set HttpContext Session Methods in BaseController vs Mocking HttpContextBase to create Get/Set methods

情到浓时终转凉″ 提交于 2019-12-02 21:20:11
I created Get/Set HttpContext Session Methods in BaseController class and also Mocked HttpContextBase and created Get/Set methods. Which is the best way to use it. HomeController : BaseController { var value1 = GetDataFromSession("key1") SetDataInSession("key2",(object)"key2Value"); Or var value2 = SessionWrapper.GetFromSession("key3"); GetFromSession.SetDataInSession("key4",(object)"key4Value"); } public class BaseController : Controller { public T GetDataFromSession<T>(string key) { return (T) HttpContext.Session[key]; } public void SetDataInSession(string key, object value) { HttpContext

Call the default asp.net HttpHandler from a custom handler

半城伤御伤魂 提交于 2019-12-02 21:02:26
I'm adding ASP.NET routing to an older webforms app. I'm using a custom HttpHandler to process everything. In some situations I would like to map a particular path back to an aspx file, so I need to just pass control back to the default HttpHandler for asp.net. The closest I've gotten is this public void ProcessRequest(HttpContext context) { // .. when we decide to pass it on var handler = new System.Web.UI.Page(); handler.ProcessRequest(context); MemoryStream steam = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);

asp.net mvc compress stream and remove whitespace

心已入冬 提交于 2019-12-02 18:34:36
So I am compressing my output stream via an action filter: var response = filterContext.HttpContext.Response; response.Filter = new DeflateStream(response.Filter), CompressionMode.Compress); Which works great. Now, I would also like to remove the excess whitespace present. I found Mads Kristensen's http module http://madskristensen.net/post/A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx . public class WhitespaceFilter : Stream { // using Mads Kristensen httpModule // http://madskristensen.net/post/A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx private Stream os; private static Regex

Request.Url.Host and ApplicationPath in one call

陌路散爱 提交于 2019-12-02 18:19:34
Is there any way to get HttpContext.Current.Request.Url.Host and HttpContext.Current.Request.ApplicationPath in one call? Something like "full application url"? EDIT: Clarification - what I need is this the part within []: http://[www.mysite.com/mywebapp]/Pages/Default.aspx I ask simply out of curiosity. EDIT 2: Thanks for all the replies, but none of them were exactly what I was looking for. FYI, I solved the problem this way (but am still interested in knowing if there's a smoother way): public string GetWebAppRoot() { if(HttpContext.Current.Request.ApplicationPath == "/") return "http://" +

What's the difference between the HttpRuntime Cache and the HttpContext Cache?

你离开我真会死。 提交于 2019-12-02 18:15:40
I know there is a very similar question here but I was hoping to get a better explination. Why would I ever use HttpContext.Cache instead of HttpRuntime.Cache if the HttpContext really uses the HttpRuntime.Cache behind the scenes? In the article Simulate a Windows Service using ASP.NET to run scheduled jobs Omar uses the HttpContext to store his cache items, but when Jeff Atwood Implemented it here he chose to use the HttpRuntime instead. Obviously in this particular situation it makes sense since since you don't have to do a web request to add the cache item back into the HttpContext. However

How can I use System.Web.Caching.Cache in a Console application?

老子叫甜甜 提交于 2019-12-02 17:59:56
Context: .Net 3.5, C# I'd like to have caching mechanism in my Console application. Instead of re-inventing the wheel, I'd like to use System.Web.Caching.Cache (and that's a final decision, I can't use other caching framework, don't ask why). However, it looks like System.Web.Caching.Cache is supposed to run only in a valid HTTP context. My very simple snippet looks like this: using System; using System.Web.Caching; using System.Web; Cache c = new Cache(); try { c.Insert("a", 123); } catch (Exception ex) { Console.WriteLine("cannot insert to cache, exception:"); Console.WriteLine(ex); } and

NHibernate thread safety with session

一个人想着一个人 提交于 2019-12-02 17:19:21
I've been using NHibernate for a while now and have found from time to time that if I try to request two pages simultaniously (or as close as I can) it will occasionally error. So I assumed that it was because my Session management was not thread safe. I thought it was my class so I tried to use a different method from this blog post http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/ however I still get the same issues. The actual error I am getting is: Server Error in '/AvvioCMS' Application. failed to lazily initialize a collection, no session or