httpcontext

ASP.NET - Get website's URL without HttpContext.Current (running in background thread)

风流意气都作罢 提交于 2019-12-24 04:00:50
问题 Bit of a long shot, but is there a way in ASP.NET to dynamically get the website's URL (http://www.example.com) when there is no HttpContext.Current available. There is no HttpContext because the code is running in a background thread* (but under the ASP.NET AppDomain). I have a background process that sends emails out every evening, and needs to include the Web address, but I don't want to hard code it because of deployments and testing (it changes from http://localhost:12345 to http:/

How to get client IP address in a one-way ASMX Web Service

会有一股神秘感。 提交于 2019-12-24 02:48:10
问题 I have a web service that is configured as one way. Or rather, the SoapDocumentMethod attribute has a property that is called "OneWay". That is set to true. I'm trying to get the IP address of the client request. I get the fact that I won't get the exact IP address because the client may be behind other networking concepts. That's irrelevant. I want an IP address of whoever initiated the call on the service, so if that's some front end server sitting on top of some clients machine, so be it.

What to use instead of HttpContext when using OWIN without System.Web

馋奶兔 提交于 2019-12-23 19:20:03
问题 We currently have a NancyFx project that we have wired up using OWIN. We are not using System.Web and we need some place to put our context that lives for the life of a request other than HttpContext. We have started implementing the context on a thread static variable so we can access the context anywhere in the application but we are worried that using Async calls will lose this thread static context. What do you use as a static accessor in lue of HttpContext when you divorce yourself from

Access TextBox value of an ASP.NET page from C# class

社会主义新天地 提交于 2019-12-23 18:55:17
问题 Say there is a TextBox on an ASP.NET page <asp:TextBox id="DateTextBox" runat="server" /> with some value set in the code-behind. How to access that value from another class of C# code-file through HttpContext or any other way? 回答1: You can access a property in you page via HttpContext even from a static method. in your page: public string DateTextBoxText { get{ return this.DateTextBox.Text; } set{ this.DateTextBox.Text = value; } } somewhere else(even in a different dll): public class Data {

Request.Form throws exception

泪湿孤枕 提交于 2019-12-23 17:49:23
问题 I am making ASP.NET Core web application, and I am uploading PDF file through HttpContext from javascript file. So, when I am trying to load file on the server side, using Request.Form.File, Form is throwing exception of type System.IO.InvalidDataException. Form message is saying: "Multipart body length limit 16384 exceeded". I tried to edit web.config file in order to increase that limit, but message is always the same. Is there anything I am missing or I am looking on the wrong side? Thanks

Alternative to HttpContext.Current.Items in ASP.NET Web Api

别说谁变了你拦得住时间么 提交于 2019-12-23 10:48:05
问题 is there a non- System.Web/HttpContext alternative to HttpContext.Current.Items, a per-request data storage? I want to save information of a request, save them and read the values from my logger (NLog). I found a good place to do this is the DefaultHttpControllerActivator/IHttpControllerActivator. This way the log messages should always look the same and the developer doesn't have much influence on the format or information provided. Edit : After some more research i found this: How can we

HttpContext.Current is null after await completed in .NET 4.5

旧街凉风 提交于 2019-12-23 10:28:42
问题 I have the following simple WCF service defined in .NET 4.5 web app: [ServiceContract] public interface IService1 { [OperationContract] [WebGet(UriTemplate = "json/DoWork/", ResponseFormat = WebMessageFormat.Json)] Task<string> DoWork(); } public class Service1 : IService1 { public async Task<string> DoWork() { Debug.WriteLine(HttpContext.Current != null); var s = await new HttpClient().GetStringAsync("http://www.google.com"); Debug.WriteLine(HttpContext.Current != null); return s; } } And

MVC UrlHelper called from Service

两盒软妹~` 提交于 2019-12-23 03:25:15
问题 I have a static class that sends emails with links to certain pages of my site. That link is getting dynamically generated with this code: UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); string url = urlHelper.Action("Details", "Product", new { id = ticketId }, "http"); The problem is I now also have a service that periodically compares the creation date with the current date and sends those mails automatically. The code crashes of course and says HttpContext

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

被刻印的时光 ゝ 提交于 2019-12-22 23:24:13
问题 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 回答1: 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

HttpContext is null in a method called inside Parallel.For

家住魔仙堡 提交于 2019-12-22 17:39:32
问题 Posting this question after trying a lot. Doing normal for is not an option because we need to do a large amount of processing in very less time. I have GetDataFor() inside which HttpContext.Current is used. The code looks like this: public void SomeMethod() { var context = HttpContext.Current; Parallel.For(0, 100, i => { var data = GetDataFor(i, context); }); } public data GetDataFor(int i, HttpContext context) { Uri requestUri = null; if (HttpContext.Current != null) { requestUri =