httpcontext

Share HttpContext code between web and non-web application

南楼画角 提交于 2019-12-22 13:02:06
问题 I've got a VB.NET module that reads from a resource file to display text in the correct language. Here's my problem - this code is shared between a web application and a non-web application, In the web application, I'm using System.Web.HttpContext to determine the user's preferred language, but now my Windows app won't even compile, because it says HttpContext isn't defined (I've already tried adding an imports for the full namespace - no dice). I would love to use some kind of try/catch

Share HttpContext code between web and non-web application

允我心安 提交于 2019-12-22 13:01:15
问题 I've got a VB.NET module that reads from a resource file to display text in the correct language. Here's my problem - this code is shared between a web application and a non-web application, In the web application, I'm using System.Web.HttpContext to determine the user's preferred language, but now my Windows app won't even compile, because it says HttpContext isn't defined (I've already tried adding an imports for the full namespace - no dice). I would love to use some kind of try/catch

Saving List<CartItem> to a Session in ASP.NET

≡放荡痞女 提交于 2019-12-22 10:54:30
问题 CartItems are saved in the the SQL database. I want to put all CartItems in a List and transfer to Instance.Items. The Instance Variable is being saved into the session. The code is below. public class ShoppingCart { public List<CartItem> Items { get; private set; } public static SqlConnection conn = new SqlConnection(connStr.connString); public static readonly ShoppingCart Instance; static ShoppingCart() { if (HttpContext.Current.Session["ASPNETShoppingCart"] == null) { Instance = new

Url Referrer is not available in WebApi 2 MVC project

最后都变了- 提交于 2019-12-22 09:40:15
问题 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

Mocking HttpContext.GetGlobalResourceObject in NUnit with Moq

◇◆丶佛笑我妖孽 提交于 2019-12-22 09:29:04
问题 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

Mock ServerVariables in the HttpContext.Current.Request

不问归期 提交于 2019-12-22 05:03:29
问题 One of my services uses server variable provided by IIS through such code var value = System.Web.HttpContext.Current.Request.ServerVariables["MY_CUSTOM_VAR"]; What I've tried is to mock those object and insert my own variable/collection and check few cases(e.g. variable is missing, value is null ...) I'm able to create instances of HttpContext, HttpRequest, HttpResponse and assign them properly however each of them is just a plain class without interface or virtual properties and

Is IISExpress Single-Threaded?

爷,独闯天下 提交于 2019-12-21 22:10:47
问题 I am in the process of writing a custom .Net app that utilizes Claims for security, since we're crossing many boundaries - web, API, batch processing and so on. During development, there are occasions where I'll create something in the system while logged in via Chrome and then I'll go to test the newly created item via a different account in Edge and somehow HttpContext.Current.User.Identity corresponds to my Chrome session. I do set Thread.CurrentPrincipal behind the scenes, but my

HttpContext Class and its Thread Safety

爷,独闯天下 提交于 2019-12-21 21:58:19
问题 I have an Singleton object in application that has following property: private AllocationActionsCollection AllocationActions { get { return HttpContext.Current.Session["AllocationOptions.AllocationActions"] as AllocationActionsCollection; } set { HttpContext.Current.Session["AllocationOptions.AllocationActions"] = value; } } I'm dealing with one error ( HttpContext.Current.Session["AllocationOptions.AllocationActions"] is null even though it is supposed to me always set to valid instance...).

NODE JS- EXPRESS: Unable to retrieve value from HTTP Context for POST and PUT requests while it works for GET

青春壹個敷衍的年華 提交于 2019-12-21 20:29:26
问题 In Node.js and Express framework, I am unable to retrieve value from HTTP Context for POST and PUT requests while it works for GET. I am using httpContext to set a unique requestId identifier so that I can use it while logging to trace API requests. I found out that HttpContext could be reset by some other packages in middle ware, is there a better way to store data for a request scope which could be accessed in all modules. app.js file const app = express(); app.use(httpContext.middleware);

What is the performance impact of tracing in C# and ASP.NET?

橙三吉。 提交于 2019-12-21 07:26:18
问题 I found this in some production login code I was looking at recently... HttpContext.Current.Trace.Write(query + ": " + username + ", " + password)); ...where query is a short SQL query to grab matching users. Does this have any sort of performance impact? I assume its very small. Also, what is the purpose of this exact type of trace, using the HTTP Context? Where does this data get traced to? Thanks in advance! 回答1: Yes it will have a performance impact whenever the TRACE conditional