httpcontext

Convert HttpContent into byte[]

社会主义新天地 提交于 2019-12-10 02:58:47
问题 I am currently working on a c# web API. For a specific call I need to send 2 images using an ajax call to the API, so that the API can save them as varbinary(max) in the database. How do you extract an Image or byte[] from a HttpContent object? How do I do this twice? Once for each image. - var authToken = $("#AuthToken").val(); var formData = new FormData($('form')[0]); debugger; $.ajax({ url: "/api/obj/Create/", headers: { "Authorization-Token": authToken }, type: 'POST', xhr: function () {

Asp.Net Mvc Can Not Log Out

时光毁灭记忆、已成空白 提交于 2019-12-09 12:56:02
问题 Here is My Code To Log In var expire = DateTime.Now.AddDays(7); // Create a new ticket used for authentication var ticket = new FormsAuthenticationTicket( 1, // Ticket version username, // Username to be associated with this ticket DateTime.Now, // Date/time issued expire, // Date/time to expire true, // "true" for a persistent user cookie (could be a checkbox on form) roles, // User-data (the roles from this user record in our database) FormsAuthentication.FormsCookiePath); // Path cookie is

HttpContext not available in Class Library

廉价感情. 提交于 2019-12-09 02:12:13
问题 I am working on a project where I have a C# class library which needs to use the System.web.HttpContext . I've done this before in another project without problem but now its not working. I'm not sure what I am missing they're both targeting .net 3.5 and I've added the reference System.web and added the directive using System.web . However, when I try and do HttpContext nothing is found. I've tried using the full path System.web.HttpContext but the only thing that comes up are 3 items related

Accessing HttpContext.Current in Data Access Layer

不羁岁月 提交于 2019-12-08 12:35:03
问题 Based on the given answer to my question at Entity Framework in layered architecture, Now I'd like to move my repositories (Which are now only responsible for CRUD abstraction, not business logic stuff) to DAL and reserve BLL for Business Logic. I've come to the conclusion that the entity context should be considered a unit-of-work and therefore not reused. So I'd like to create an obejctcontext per HttpContext in my repositories to prevent performance/thread [un]safety issues. I'd like to

ASP.NET MVC : How to create own HttpContext

人盡茶涼 提交于 2019-12-08 04:59:26
My idea was to create my own HttpContext which will include some of the internal objects used in our app. So I thought I will simply create public class FooHttpContextBase : HttpContextBase { public string Foo { get { return "Boo"; } } } And then override HttpContext property: public abstract class BaseController : Controller { private FooHttpContextBase context; public BaseController() { context = new FooHttpContextBase(); } override public HttpContextBase HttpContext { get { return context; } } } But then I've realized HttpContext is not a virtual - so it cannot be overridden. Well, what do

ASP.NET MVC : How to create own HttpContext

喜欢而已 提交于 2019-12-08 04:15:57
问题 My idea was to create my own HttpContext which will include some of the internal objects used in our app. So I thought I will simply create public class FooHttpContextBase : HttpContextBase { public string Foo { get { return "Boo"; } } } And then override HttpContext property: public abstract class BaseController : Controller { private FooHttpContextBase context; public BaseController() { context = new FooHttpContextBase(); } override public HttpContextBase HttpContext { get { return context;

“System.Web.HttpException: Response is not available in this context” only in IIS

倖福魔咒の 提交于 2019-12-08 03:56:10
问题 i have used the Http.Current.Response in my global.asax.cs Application Start. It is working fine without any issue when i execute in my PC. How ever when i try to put it in IIS with Windows Server 2008 R2, i find that it is giving the following error. the code for it is public static void SetCookie(string key, string value, int dayExpires) { HttpCookie encodedCookie = HttpSecureCookie.Encode(new HttpCookie(key, value)); encodedCookie.Expires = DateTime.Now.AddDays(dayExpires); HttpContext

Empty HttpContext.Current.Request.Files in WCF Service

若如初见. 提交于 2019-12-08 03:10:07
问题 I'm trying to upload files form a html5 page to a WCF Service but the Files object in the HttpContext.Current.Request is empty. Any Idea? my WCF Service: [ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class FileUploader { // test file uploader [OperationContract] [WebGet] public string UploadFile() { string fileName = "no file selected"; HttpContext context = HttpContext.Current; if (context != null) {

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

天涯浪子 提交于 2019-12-08 02:56:32
问题 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

How could I access the ViewState of the current page using HttpContext?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 23:16:16
问题 How could I access the ViewState of the current page using HttpContext I have a ViewStateUtil class that I'd need to implement: public static T GetViewState<T>(ViewStateKey viewStateKey) { // how to implement it?! HttpContext.Current...? } 回答1: private static T GetViewState<T>(string name) { return (T) ((BasePage)HttpContext.Current.CurrentHandler).PageViewState[name]; } I added a new PageViewState property and let all my pages inherit from my BasePage to expose ViewState then being able to