Usage Of HttpContext.Items Dictionary Object
Feb 1, 2011When and how do I use the Httpcontext.items dictionary object?
View 2 RepliesWhen and how do I use the Httpcontext.items dictionary object?
View 2 RepliesCan you iterate through a dictionary object that can contain a object and enum types
foreach(Dictionary<someObject, enumType> myDic in myObjects) {
if(enumType.myType == enumType.Type) {
do something here...
}
What would be the best way to deserialize this
Dictionary<string, object>{
{"fName", "John"},
{"lName", "Doe"},
{"email", "john@doe.net"}
}
to this
class Member{
string fName;
string lName;
string email;
}
In MVC3 Beta version i have action result same like
public ActionResult Save(Dictionary<string, string> dicObject)
I want to pass JSON Object in POST Method from javascript and need to get as dictionary object
How can i do this? can you write example if possible?
I've just updated my ASP.Net code from HttpContext.RewritePath(targetPath) to use the .Net 3.5 function: HttpContext.Server.TransferRequest(targetPath,true)
However, I now no longer have any of the custom HttpContext.Items that I added, before the transfer.
How do you sort a dictionary object in C# 2.0 for asp.net or is their an alternative to Dictionay for sorting this is to sort a countries list alphabetically
View 3 RepliesI was under the impression that you could use the HttpContext.Current.Items collection to pass information between pages but it doesnt seem to workLets say i have a Page1 ButtonClick, the button click handler stores a value in the collection like so; HttpContext.Current.Items("Test1") = "Test"Then i do Response.Redirect("Page2.aspx").In the Form_Load of Page2, HttpContext.Current.Items("Test1") contains nothing. Why does this not work when its all part of the same postback?This would be perfect, because i wouldnt need to worry about clearing the values between requests because they would automatically get cleared each time the page was posted back.
View 5 RepliesI am iterating through a dictionay object. And although I added a couple of keys @Microdoft and @Microsoft_Child which I thought were different but when i use the .ContainsKey method it views them as being the same. Should I use ContainsValue method?
View 3 RepliesI checking to see if we have any way to return all the keys to array without using the for each loop (there is no constraint for me to use for each loop i am just looking is there any other way)
View 3 Repliescan i add string builder object to a dictionary object? If yes code it. I mean i have a dictionary in which i have already added a few (string, objects), and i have a string Builder which has few variable already added now i want that instead of passing 2 different object in a method i want to pass only one object so can i add string builder object to same method as well
View 2 RepliesI'm using HttpContext.Current.Items to make a Per-Request Cache Store. I'm hitting to many Cache entries over different http requests.
It seems that HttpContext.Current.Items is reused across multiple http requests. Is it normal?
In a page (not default) I have:
Protected
Sub Page_Load(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles
Me.Load
Try
loginRep = BusinessLogic.SR.GetUserName("99999")
System.Web.HttpContext.Current.Items.Clear()
System.Web.HttpContext.Current.Items.Add("RepId",loginRep)
I don't any errors and when in the run in the immediate window:
? System.Web.HttpContext.Current.items("RepId") in the immediate window on THAT page I get the OBJECT.
Then I have a hyperlink with navigateurl to the next page "~/ActCnt.aspx"
On that page, ActCnt.aspx, when in the code I have:
Protected
Sub Page_Load(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles
Me.LoadIf
Not Page.IsPostBack
Then
Dim loginRep
As BusinessLogic.SalesRep = System.Web.HttpContext.Current.Items("RepId")
In the immediate window ? System.Web.HttpContext.Current.Items("RepId") returns a String that is equal to "RepId".
Even if I change it to not be an object, but a string I only get the Name "RepId" of the keypair. I have NEVER gotten the actual value.
If a html helper takes a idictionary as a parameter, how do I use it?I tried:<%= Html.Blah( new { id = "blah" }) %>
View 3 RepliesI've got a Dictionary<string, string> object I'm creating:-
[Code]....
and I wanted to bind this to a dropdownlist. I know this is possible in code-behind, but is it possible to do this directly on the asp: control, something like
I am trying to use
[Code]....
with values I get from a database but I am getting Object reference not set to an instance of an object.
How can i identify just from the HttpContext Object that the HttpRequest coming to my application is from a cookieless application or cookieless browser?
View 2 RepliesI have a class that maintains a static dictionary of cached lookup results from my domain controller - users' given names and e-mails.My code looks something like:
private static Dictionary<string, string> emailCache = new Dictionary<string, string>();
protected string GetUserEmail(string accountName)
{
if (emailCache.ContainsKey(accountName))
{
return(emailCache[accountName]);
}
lock(/* something */)
{
if (emailCache.ContainsKey(accountName))
[code]...
We're migrating an application to use IIS7 integrated mode. In library code that is designed to work either within the context of an HTTP request or not, we commonly have code like this:
if (HttpContext.Current != null &&
HttpContext.Current.Request != null) {
// do something with HttpContext.Current.Request
} else {
// do equivalent thing without HttpContext..
}
But in IIS7 integrated mode the check for HttpContext.Current.Request throws an exception whenever this code is called from Application_Start.
protected void Application_Start(object sender, EventArgs e)
{
SomeLibrary.DoSomethingWithHttpContextCurrentDetection();
}
Results in:
System.Web.HttpException: Request is not available in this context
How can I detect whether the request is really available without wrapping these calls in an exception handler and taking action based on whether an exception is generated or not.
Looking at HttpContext in Reflector I see it has an internal bool HideRequestResponse field but it's internal so I can only get to it with reflection and that's fragile. Is there a more official/approved way to determine if it's ok to call HttpContext.Request?
This blog post about the subject says not to use HttpContext, but how, in generic library code, can you determine if it's ok to use HttpContext?
http://mvolo.com/blogs/serverside/archive/2007/11/10/Integrated-mode-Request-is-not-available-in-this-context-in-Application_5F00_Start.aspx
I'm using the work-around mentioned there which is to use Application_BeginRequest and an initialized field to only initialize once as part of BeginRequest, but that has to be done in every calling application whereas I'd prefer to make the library code more robust and handle this situation regardless of where it's called from.
I am a beginner ASP.NET C# developer and have a question about a concept. When I declare a function, I have something generic like:
public void sample_function(object sender, EventArgs e)
{
//function code
}
What I want to know is what does the "object sender and EventArgs e" stand for? How can I use these?
public class Package
{
public Package()
{
name = "";
type = new List<Dictionary<string, string>>();
}
public string name { get; set; }
public List<Dictionary<string, string>> type { get; set; }
}
[code]...
I need to load an XML document into my Dictionary<string,string> object.XML looks like:
<nodes>
<node id="123">
<text>text goes here</text>
</node>
</nodes>
How can I do this using XmlDocument?I want readability over performance, and I find XmlReader to be hard to read b/c you have to keep checking the node type.
I want to create a Dictionary... where i can get Dictionary database or World lists (english to english , english to hindi)
View 1 RepliesI'm using DropDownList within my WebApplication. I need to keep additional piece of information with each Item on list. How can I achieve this?
View 3 RepliesI have a DataView object with productID and productName,i get all items from Products Table and store them in Cache.I want to get items that user bought in order he bought them without using another query or joining tables. ie.
Products DataView
1. Foo
2. Foo2
3. Foo3
Filtering to ProductsBoughtByUser using RowFilter (productID in (1,3))
UserProducts DataView
1.Foo
3.Foo3
Now user first bought Foo3, how do i reorder items based on correct ( chronological ) Array. ie 3 1
For my site, I have a list of users and a list of events. I will be assigning users to each event. I have a table named EventUsers to hold this data:
EventUsers
EventID | UserID
1 | 123
1 | 456
2 | 789
On my page, I want to be able to add and remove users for a certain event. I could have a dropdown populated with users and an "Add" button next to it, then when I want to add a user, I pick one and click "Add". There would be a grid below it displaying all the users for the event, with "Delete" buttons for each one. The downside to this is that a database call is made for every Add and Delete.
Another option is to have two listboxes on the page - one on the left containing all users in the database, and another on the right which will contain users for the given event, and I can just add or remove from the list on the right. Then when I'm done, I click save, and it makes one database call. The only issue is that if I'm removing and adding, I'll have to delete every record in my EventUsers table for that event, and then add the changes. I've run into this before, and I've always gone with the dropdown method. What's the preferred method here?