httpcontext

Why should I move away form using HTTPContext Session State in my ASP .Net MVC applications?

佐手、 提交于 2019-12-06 14:01:29
I recall reading a couple of places that folks are discouraging the use of HTTPContext.Current.Session state in ASP .Net web applications. Can someone explain some of the reasoning behind this recent trend? ARe there solid technical reasons for this? Thanks, JohnB Adam Heeg First, MVC is not webforms, it is meant to be stateless. http://www.wintellect.com/blogs/jprosise/thoughts-on-asp-net-s-new-mvc-framework Second, MVC is restful in nature http://dotnetslackers.com/articles/aspnet/AnArchitecturalViewOfTheASPNETMVCFramework.aspx and according to stack overflow (lol) sessions are not restful.

SP2010 - httpcontext.response.write() not working for LinkButton's onClick event

为君一笑 提交于 2019-12-06 05:26:11
probably a simple oversight I've missed (though I vaguely recall some obscure blogpost about the inner workings of Response.Write not working as expected in some situations but I don't remember if this is one of them): The situation is, I have a Link Button on a control running in SP2010, and if I don't use HttpContext.Response.Write(), everything works as expected (ie I can change the .Text value for a Label). However, if I call Context.Response.Write(), while I can debug and step through the code, nothing seems to happen any more (nothing is written back and changes to other controls do not

Url Referrer is not available in WebApi 2 MVC project

烂漫一生 提交于 2019-12-05 22:05:38
I have an MVC WebAPI 2 project with a Controllers controller. The Method I'm trying to call is POST (Create). I need to access the referring URL that called that method yet, no matter what object I access, the referring URL either doesn't exist in the object or is null. For example, I've added the HTTPContext reference and the following returns null : var thingythingthing = HttpContext.Current.Request.UrlReferrer; The Request object does not have a UrlReferrer property. This returns null as well: HttpContext.Current.Request.ServerVariables["HTTP_REFERER"] I cannot modify the headers because I

Web API Service - How to use “HttpContext.Current” inside async task

妖精的绣舞 提交于 2019-12-05 20:51:36
问题 I'm using a "Post" async method of webApi rest service: public async Task<object> Post([FromBody]string data) { object response = ExecuteServerLogics(data); return response; } This above code worked good but in some of the client's calls, we experienced performance issues. After reading some articles here, i've noticed that our webApi rest service, is not really working asynchronously with its incoming web requests, because we forgot to use async/await pattern : public async Task<object> Post

Mocking HttpContext.GetGlobalResourceObject in NUnit with Moq

匆匆过客 提交于 2019-12-05 18:44:38
I am trying to write a unit test which tests a method that uses HttpContext.GetGlobalResourceObject() and I would like to mock it using Moq. Let's say we're testing this method: public List<DctmGridColumn> GetDctmColumnsMandatory() { List<DctmGridColumn> metadataFields = new List<DctmGridColumn> { new DctmGridColumn(HttpContext.GetGlobalResourceObject("SharePoint.Service", "DctmGridColumn_DispName_r_object_id").ToString()), new DctmGridColumn(HttpContext.GetGlobalResourceObject("SharePoint.Service", "DctmGridColumn_DispName_object_name").ToString()), new DctmGridColumn(HttpContext

Determine the URL hostname without using HttpContext.Current?

好久不见. 提交于 2019-12-05 12:03:49
问题 Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But - I need to determine the URL hostname without using the current request ( HttpContext.Current ). The reason for this is that my code is called from a SqlDependency in the onChange callback for when a SQL Dependency is found. Althougth the code resides in my web app, there is no request, and HttpContext.Current is null. I was hoping I could grab it from HttpRuntime , but there doesn't seem to

In MVC3, how to get the current controller name?

柔情痞子 提交于 2019-12-05 10:13:05
From the http context class is there a method to get the current Controller name? Yes, you can do something like that HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString(); If you're in a view, then you can do: ViewContext.RouteData.Values["Controller"] 来源: https://stackoverflow.com/questions/14462751/in-mvc3-how-to-get-the-current-controller-name

How to initialise a custom HTTP Context or HttpContextBase

人走茶凉 提交于 2019-12-05 08:47:39
I am experimenting with creating my own custom HTTP Context: CustomHttpContext : HttpContextBase { public override HttpRequestBase Request { } } One thing i can't figure out is how to initialize the base class with System.Web.HttpContext.Current Does anyone have any ideas how i can initialise the custom context first with the Current Http then override certain Methods/Properties to serve my own purpose? dash The simple answer is no, it's not possible. Also note that HttpContext does not inherit from HttpContextBase, instead, they both implement IServiceProvider. Finally, HttpContext is sealed,

HttpContext.Current.Items cleared via responseMode=“ExecuteURL”?

匆匆过客 提交于 2019-12-05 08:36:56
I avoid the default ASP.NET approach of redirecting on errors (as many people do). Clean AJAX code and SEO are among the reasons. However, I'm using the following method to do it, and it seems that I may lose HttpContext.Current.Items in the transfer? <httpErrors errorMode="Custom" existingResponse="Replace"> <remove statusCode="401" /> <remove statusCode="403" /> <remove statusCode="404" /> <remove statusCode="500" /> <error statusCode="401" responseMode="ExecuteURL" path="/Account/SignIn" /> <error statusCode="403" responseMode="ExecuteURL" path="/Site/Forbidden" /> <error statusCode="404"

How to pass HttpContext.Current to methods called using Parallel.Invoke() in .net

只愿长相守 提交于 2019-12-05 08:11:48
I have two methods which makes use of HttpContext.Current to get the userID. When I call these method individually, I get the userID but when the same method is called using Parallel.Invoke() HttpContext.Current is null. I know the reason, I am just looking for work around using which I can access HttpContext.Current. I know this is not thread safe but I only want to perform read operation public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Display(); Display2(); Parallel.Invoke(Display, Display2); } public void Display() { if