httpcontext

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

空扰寡人 提交于 2019-12-07 18:41:29
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.Current.Response.Cookies.Remove(key); HttpContext.Current.Response.Cookies.Add(encodedCookie); } I wanted

Empty HttpContext.Current.Request.Files in WCF Service

可紊 提交于 2019-12-07 08:38:26
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) { if (context.Request.Files.Count > 0) { fileName = context.Request.Files[0].FileName; } } return

HttpContext in MVC Attributes - threading issues?

本小妞迷上赌 提交于 2019-12-07 07:56:57
问题 I had my NHibernate session management setup like follows: protected MvcApplication() { BeginRequest += delegate { NHibernateSessionManager.Instance.OpenSession(); }; EndRequest += delegate { NHibernateSessionManager.Instance.CloseSession(); }; } And for when I needed to save to the database, I made an ActionFilterAttribute that looked like this: public class TransactionAttribute: ActionFilterAttribute { private ITransaction _currentTransaction; public override void OnActionExecuting

How to initialise a custom HTTP Context or HttpContextBase

倾然丶 夕夏残阳落幕 提交于 2019-12-07 05:09:36
问题 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? 回答1: The simple answer is no, it's not possible. Also note that HttpContext does not

In MVC3, how to get the current controller name?

好久不见. 提交于 2019-12-07 04:46:53
问题 From the http context class is there a method to get the current Controller name? 回答1: 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 pass HttpContext.Current to methods called using Parallel.Invoke() in .net

荒凉一梦 提交于 2019-12-07 03:10:17
问题 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

Passing HttpContext.Current.User.Identity to WCF

二次信任 提交于 2019-12-07 02:34:19
问题 Looking for a little advice (or maybe even a direct answer). I have an MVC3 website. I also have a set of WCF services running (for now everything is on the same box). What I'm trying to do is authenticate the client (that part is working fine), then pass that authenticated user on to various WCF calls. At the moment I've hooked up the Application_AuthenticateRequest() method in Global.Asax , which boils down to creating a new GenericIdentity & GenericPrincipal , then assigning that principal

Why mock HttpContext if it can be constructed?

限于喜欢 提交于 2019-12-07 00:55:33
问题 I have always been faking/mocking/stubbing HttpContext somehow in ASP.NET (much easier in ASP.NET MVC/MonoRail). But I can see that HttpContext itself can be constructed easily, literally with couple of lines of code. var tw = new StringWriter(); var workerReq = new SimpleWorkerRequest("/webapp", @"c:\here\there\wwwroot", "page.aspx", tw); var context = new HtpContext(workerReq); If we'll wrap this code into something like this it should work fine, and probably we can even render ASPX using

How to use Server.MapPath when HTTPContext .Current is Nothing

白昼怎懂夜的黑 提交于 2019-12-06 17:24:54
问题 I have some code that works fine when I need to delete some image files from a directory on my web server: Dim ImageURL As String = dsImages.Tables(0).Rows(iImgRow).Item("ImageURL") Dim physicalName = Server.MapPath(ImageURL) oUpload.DeleteFileFromServer(physicalName, iAdid, iImgID) ..but I am running into a problem when a maintenance task running in a separate thread at set intervals determines that files like the above need to be deleted: Dim ImageURL As String = dsImage.Tables(0).Rows(i -

ASP.NET MVC 4 How to manage userid and user content inside controllers

孤者浪人 提交于 2019-12-06 16:00:33
问题 To learn the ASP.NET MVC 4 patter I'm developing and application that has to manage some data and user content. This is the database: public DbSet<UserProfile> UserProfiles { get; set; } public DbSet<Fund> Funds { get; set; } public DbSet<Source> Sources { get; set; } public DbSet<Portfolio> Portfolios { get; set; } public DbSet<Quote> Quotes { get; set; } public DbSet<Deposit> Deposits { get; set; } Where relationship cardinalities are: UserProfile (a user) - Portfolio: 1-N UserProfile -