httpcontext

Using HttpContext.Current.Application to store simple data

♀尐吖头ヾ 提交于 2019-11-27 02:46:27
问题 I want to store a small list of a simple object (containing three strings) in my ASP.NET MVC application. The list is loaded from the database and it is updated rarely by editing some values in the site's admin area. I'm thinking of using HttpContext.Current.Application to store it. This way I can load it in the Global.asax: protected void Application_Start() { RegisterRoutes(RouteTable.Routes); HttpContext.Current.Application["myObject"] = loadDataFromSql(); // returns my object } And then

Get application path without using httpcontext. (asp.net)

懵懂的女人 提交于 2019-11-27 01:00:21
问题 How to do it? I don't want to use this: HttpContext.Current.Server.MapPath Is there a similar function that I can call without requiring a httpcontext? For example if a start a thread doing some stuff i cant use the httpcontext, but i still need to get the path of the app. And no i can't pass the context as an argument or read it from a shared var. 回答1: Use the HttpRuntime.AppDomainAppPath property. 回答2: There are several options: HttpRuntime.AppDomainAppPath WebApplication -> Web root folder

How to get working path of a wcf application?

谁说胖子不能爱 提交于 2019-11-27 00:33:58
I want to get the working folder of a WCF application. How can I get it? If I try HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath) I get a null reference exception (the Http.Current object is null). What I meant with the working folder was the folder where my WCF service is running. If I set aspNetCompatibilityEnabled="true" , I get this error: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error. I needed the same information for my IIS6 hosted WCF application and I

Is it possible to set a cookie during a redirect in ASP.NET?

妖精的绣舞 提交于 2019-11-26 23:10:53
问题 I am using ASP.NET. I either add or set a cookie (depending on whether the HttpRequest contains a cookie with specified key), and immediately afterward call Response.Redirect . The cookie is not set. Is this correct behavior? Is there something mutually exclusive about setting a cookie during an http response with a 302 status code? Here's the source: if (context.HttpContext.Request.Browser.Cookies) { var cookies = context.HttpContext.Request.Cookies; var stateCookie = new HttpCookie(SR

Why is HttpContext.Current null?

给你一囗甜甜゛ 提交于 2019-11-26 22:57:30
I have a value that I use in all the application; I set this in application_start void Application_Start(object sender, EventArgs e) { Dictionary<int, IList<string>> Panels = new Dictionary<int, IList<string>>(); List<clsPanelSetting> setting = clsPanelSettingFactory.GetAll(); foreach (clsPanelSetting panel in setting) { Panels.Add(panel.AdminId, new List<string>() { panel.Phone,panel.UserName,panel.Password}); } Application["Setting"] = Panels; SmsSchedule we = new SmsSchedule(); we.Run(); } and in SmsSchedule public class SmsSchedule : ISchedule { public void Run() { DateTimeOffset startTime

System.Web.HttpContext.Current.User.Identity.Name Vs System.Environment.UserName in ASP.NET

亡梦爱人 提交于 2019-11-26 20:55:03
What is the difference between System.Web.HttpContext.Current.User.Identity.Name and System.Environment.UserName in the context of a ASP.Net Web Application Project? Here's the code of what I'm trying to do: Database myDB = DatabaseFactory.CreateDatabase(); bool IsAuthUser = myDB.ExecuteScalar("procIsAuthorizedUser", System.Environment.UserName); If they are functionally identical, which is better in terms of performance? This is a C# 4.0/ASP.Net web application which will see moderate usage internally in the organization. Thank you for the answers. System.Environment.UserName returns the

Request.UserHostAddress issue with return result “::1”

六眼飞鱼酱① 提交于 2019-11-26 20:34:15
问题 I am trying to get client ip address using HttpContext.Request.UserHostAddress; but it returns ::1 . How to solve this? 回答1: ::1 is for localhost , Maybe this might be useful. 回答2: This is not a bug - you're connecting from localhost on an IPv6 enabled machine. ::1 is the loopback address - a double colon means "omitted zeroes", so this address corresponds to address 1. If you're developing new software, I'd urge you not to disable IPv6. The easiest time to implement support is right from the

elmah: exceptions without HttpContext?

萝らか妹 提交于 2019-11-26 19:49:16
问题 I spawn a thread on Application_Start and would like to log exceptions. There is no Context/HttpContext/HttpContext.Current , so how might I get it to log? At the moment, it does not catch any exception in my threads and if I write ErrorSignal.FromCurrentContext().Raise(ex); I get an error about context cannot be null. Maybe I can create a dummy HttpContext but somehow I don't think that will work well. -edit- I tried ErrorSignal.Get(new HttpApplication()).Raise(ex); and it doesn't seem to

access HttpContext.Current from WCF Web Service

爱⌒轻易说出口 提交于 2019-11-26 19:24:15
问题 I just started using WCF Services with ASP.NET AJAX. I instantiate my WCF service from Javascript and then pass string variables as arguments to my WCF Service method (with an OperationContract signature). I then return a .NET object (defined with a DataContract) which is bound to my custom Javascript class. I'm having trouble authenticating based on the user logged into my web session. However, the WCF web service is a completely different service with no context to the HttpContext.Current

How do I get an HttpContext object from HttpContextBase in ASP.NET MVC 1?

坚强是说给别人听的谎言 提交于 2019-11-26 19:04:00
问题 I'm working with some WebForms/MVC-agnostic tools, and I need to get an instance of HttpContext given a reference to an HttpContextBase object. I can't use HttpContext.Current because I need this to work asynchronously as well ( HttpContext.Current returns null during an asynchronous request). I'm aware of HttpContextWrapper , but goes the wrong way. 回答1: The simplest way is to get the application, ApplicationInstance, and use its Context property: // httpContextBase is of type