MVC :: Access The Session On The Controller?

Jan 30, 2010

I am trying to get into grips with AJAX/JQuery and MVC. i need to access the session on the controller. This doesnt seem to be initialised at the constructor level but there needs to be a way I can store items in the session in the constructor depending on the parameter values (an extra constructor is written here) I am also doing unit testing here, which has been provided by 3rd party and they are using this extra constructor.

So the idea here is that when the page is loaded, JQuery will request a collection of items (which will be stored in session) and also be able to post to the page so items are added into the collection too. So, what is the best way here to get access to the session in the constructor of a controller?

View 4 Replies


Similar Messages:

MVC :: Access HTTPContext And Session From Custom Base Controller Class?

Jan 13, 2010

I built a base controller class inherits from Controller class to add some custom behavior to all controllers which will inherit from this base class.

My issue is when I try to access HTTPContext and Session objects in my custom base class, they are always null.

Am I doing something wrong or need missing something?

My custom base class definition:

public class ApplicationControllerBase : Controller

controllers classes definition:

public class HomeController : ApplicationControllerBase

using ASP.NET MVC 1, .NET 3.5.

UPDATE:

It seems the issue is I try to access HTTPContext in the constructor while HTTPContext is not ready yet, I tried it in the OnActionExecuted event handler and it works fine.

My question is what is the best place to access Session object in my custom controller class, that will guarantee executing my code with all controllers.

View 3 Replies

MVC :: Session Vs TempData / How To Persist Values From Controller To Controller

May 30, 2010

I have a filter on my MVC web site. I display some records in a few different controller actions but when moving from one action to another I want to apply those filter values.

How can I persist values from controller to controller?

Should I use Session? TempData?

I am using Structure Map for IOC.

Maybe I could have a class that contains a Property for each Session Value that I use in my application and inject it on the controllers that need session?

View 10 Replies

MVC ::Session Variables Called From The Owning Controller?

Feb 19, 2011

I'm calling an action from another controller using this code

[Code]....

But inside "ApproveOperation" action, I needed the Session variables. It seems when I called it from another controller (not the owning controller), the Session variables can not be accessed (null value).How can I get the same Session variables just like it was called from the owning controller?

View 4 Replies

Implement Cross-session Data Controller Class?

Feb 24, 2011

I am creating an ASP.NET application that allows users to edit and insert data that is persisted in a SQL Server database.I would like to implement a controller class that handles queries for certain entities, caches results and triggers events when data is inserted or updated.I need one of these controller classes for each entity in my data model.What I'm unsure of is how to create a singleton class of this sort that different user sessions can access.

For example,I have a Employee entity in my data model.I would like to have an EmployeeController class that handles retrieving the employees from the database, sends inserts and updates to the database,keeps a cache of all employees and triggers events when an employee is inserted or updated.Objects in other user sessions could then listen and respond to these events.

Am I on the right track?Should I be using the ASP.NET MVC framework to accomplish this?How do I instantiate these controller classes when the first user needs them and have subsequent concurrent users access the same class?

EDIT:I've been researching the idea of a controller class as an anti-pattern since @TomTom's answer.I'm not convinced one way or the other.I still need an answer to question #3 above.Let's just drop the specific idea of a controller class for now. How do I create any class that is:accessible by multiple user sessions,allows only one instance,is deleted if there are no user sessions,and triggers events that other classes can listen to.

View 2 Replies

MVC :: Use The Same View To Access The Different Controller?

Jan 18, 2011

I am new to MVC. Now I have an application needs to be built using MVC. I want to show all the information in one view(or form), but the data are coming from different controllers. how the system knows the data in textbox1 goes to controller1 and the data from database in controller2 returns to textbox2 in the same view(or form)?

View 7 Replies

C# - Using Grasp Controller With MVC Controller - How To Make An Object Always Visible For A Controller

Dec 28, 2010

UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, that follows the UP(Unified Process). It uses a Grasp Controller pattern to interact with domain classes by some methods like NewSale(), AddNewItemToSale() and CloseSale. In windows form, I can instantiate a object of this class in the UI and then use its methods to perform the actions. This works well in Client apps, but when I use asp.net mvc, I cannot find a way to instantiate an object (one for each user) that was always visible for a Controller (MVC). I cannot insert as an attribute inside Controller because it always create a new one.

View 1 Replies

Access The HttpServerUtility Instance In MVC Controller?

Nov 17, 2010

How can I access the HttpServerUtility instance in ASP.NET MVC controller?

View 1 Replies

MVC :: Access A Control In The Page Controller?

Mar 6, 2011

My question is if i put a dropdownlist on my webpage:

[Code]....

How do i acces this from my controller. If for example i want to make it visible or not?

View 2 Replies

MVC :: Can Access Masterpage Dropdown Value In Controller Action

Jan 17, 2011

I have a masterpage on which i displays groups that user can access now i want to gets its selected value in other controllers for saving with the records. I want to know if it is possible in asp.net mvc 2 and if not then what is the way around for it

View 1 Replies

MVC :: Calling Controller Action Using Jquery Post Ajax Call Abondons Session?

Apr 9, 2010

i have a website where i provicde a link. On clicking the link a controller action method is called to generate a zip file after creation of zip file is done, i show the link to download the zip file by replacing the link to create a zip with the link to download the zip.

the problem is that after zip file creation is over and link is shown, when user clicks on the link to download the zip file, they are sent to login. After providing correct credentials in the login page they are prompted to download the zip file. they sould not be sent to the login page. In the action to generate zip file i haven't abondoned the session or haven't not done anything that abondons the session.

the user should not be sen't to login page after successful creation of zip file user should be able to download the file without login. i search internet on this problem, but i did not find any solution. In one of the blog written by hanselman i found this statement that creates the problem with the session: Is some other thing like an Ajax call or IE's Content Advisor simultaneously hitting the default page or login page and causing a race condition that calls Session.Abandon? (It's happened before!)

so i thought there might be some problem with ajax call that causes the session to expire, but i don't know what is happening? it's like this after users click on the link to create zip file the zip file is created successfully but the session gets expired. this is not what i want. Why does the session has to get expired after making a jquery post call to controller action to create a zip file? i hope u understand the problem.

View 5 Replies

MVC :: Access Values In Text Boxes(generated In View) From Controller

Feb 28, 2011









View 1 Replies

Access :: Access/SQL Selectcommand And Session?

Nov 22, 2010

I have the following two pages. One is a search page that have a few listbox/textbox/and dropdownlist. The other will be the result page that take from session those 3 data and using an if/else statement to sort out some detail. After that it will form an access/sql selectcommand to search the database base on that 3 criteria. But for some weird reason only the first part of my if and else statement work. Can anyone check and help me out why the rest of the if/else doesn't work. Or point me to another direction?


---------------------Search.aspx-----------------------------

[Code]....

-------------------SearchResult.aspx-----------------------
[Code]....

[Code]....

View 3 Replies

MVC :: Out Of The Box MVC2 Controller / Delete Controller Is Refusing To Return Any Class Information

Nov 6, 2010

my MVC2 delete and only my delete controller is refusing to return any class information. Its really similar to my edit function and the views are all auto-generated so I don't see the problem.

Function Delete(ByVal id As Integer) As ActionResult

View 4 Replies

How To To Access The Session In A WebMethod

Dec 7, 2010

I have a pagemethod defined with the attribute [WebMethod]. The pagemethod accesses the session with no problem (HttpContext.Current.Session).

However I just read somewhere that in order to access the session in a WebMethod, you need to define it like so: [WebMethod(EnableSession=true)]

So my question is, what gives? How come I can access the session even though I dont have that code? Apparently EnableSession defaults to false if its missing, so I should not be able to access the session. The web application uses ASP.NET 3.5 and uses InProc Cookieless sessions.

View 5 Replies

MVC :: Pass Parameter From Controller To View And Back To Another Controller?

Aug 16, 2010

I have a simple model where a Person has Gifts. I have a view which is a list of Gifts belonging to one Person.

My problem is with the Create action for a new Gift. I want it to default to the PersonID that we are already viewing the list of Gifts for. I tried simply passing the last PersonID (they are all the same)

Html.ActionLink("Create New", "Create", new { id = Model.Last().PersonID }) which works fine if there is already at least one Gift for that person but if this is the first Gift I don't have a value.

My Gift List controller knows the PersonID I want to pass but the view doesn't.

How do I pass this PersonID from my Gift List controller to my Gift Create controller via the Gift List view? Or is there a better way to do this?

View 2 Replies

How To Access Session Value At Client Side

Apr 20, 2010

I want to access the session value at client side.

Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
btnGetSessionValue.Attributes.Add("onclick", "javascript:return GetSessionValue();");
}
}
[code]...

View 3 Replies

Access Session Variable In Facebook C# SDK?

Mar 18, 2011

I've my ASP.Net HTML 5 Application, Which have the image byte array in Session, I'm using the Latest 5.X C# facebook SDK from CodePlex.

But when user is authorized and Coming back to my canvas page at that time I can't access my ASP.Net Session, its give me a null value.

Here is my Code.

[code].....

Now pls give me some suggestion, Where I'm missing, How can I access my Application Session.

View 1 Replies

How To Access The Session From A Different Project Within The Solution

Feb 4, 2010

I have 2 projects in my solution.

MVC Web application
Class library

The MVC Web application references the class library.

The class library contains a class that extends the default ASP.Net Controller.

I'm putting a variable in session in the application's Global.asax.

protected void Session_Start(object sender, EventArgs args)
{
HttpContext.Current.Session["DomainName"] = Request.Url.Host;
}

In the class library I'm trying to get the value from the HttpContext.Session, but HttpContext.Session keeps coming up null.

[code]...

HttpContext.Current.Session doesn't seem to be an option in controllers.

View 3 Replies

C# - Access Session Value During Concurrent Requests

Mar 9, 2010

in one request i am updating session variable. in the other request, i am trying to access that session value, but it was blocked until the first request finish. I am using C# with ASP.NET 2.0 UPDATE: My page code looks like this.

while(int progress = DoWork() && progress <= 100 ){
Session["Progress"] = progress;
}

and my handler just return Session value.

context.Response.Write(Session["progress"].toString());
context.Response.End();

View 1 Replies

C# - Synchronizing Access To A Member Of The Session?

Apr 26, 2010

I'm building a Javascript application and eash user has an individual UserSession. The application makes a bunch of Ajax calls. Each Ajax call needs access to a single UserSession object for the user.

Each Ajax call needs a UserSession object.

Data in the UserSession object is unique to each user.

Originally, during each Ajax call I would create a new UserSession object and it's data members were stored in the ASP.NET Session. However, I found that the UserSession object was being instantiated a lot. To minimize the construction of the UserSession object, I wrapped it in a Singleton pattern and sychronized access to it.

I believe that the synchronization is happening application wide, however I only need it to happen per user. I saw a post here that says the ASP.NET cache is synchronized, however the time between creating the object and inserting it into the cache another Thread could start construction it's another object and insert it into the cache.

Here is the way I'm currently synchronizing access to the object. Is there a better way than using "lock"... should be be locking on the HttpContext.Session object?

[code]...

View 2 Replies

How To Access The Session In Order To Do A Rewrite

Sep 21, 2010

I'm trying to use the HttpContext.Current.RewritePath method to serve up different versions of an application to different customers. I would love to be able to look at the HttpContext.Current.Session object to know who it is making the request. Oddly when I go to look at this at the BeginRequest handler, the Session always shows null. I've tried various other events and have had no luck.

View 1 Replies

C# - Access Session Variable In Session_End?

Oct 14, 2010

in my web app users login to website normally and they have tagged in user table in database as online user in Session_End i want to log them outIn Session_End i have no access to HttpContext.Current.Session or Session only they are both null how can i access to session variable at (Session_End) event.

View 1 Replies

Access The User Session From A Web Method?

Oct 29, 2010

I want to access the user session from a web method. But when I check for the session object, its nothing! How can I access the current user's session from the webmethod?

My code:

<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _.......

View 2 Replies

Access :: Subtract Session Value Before Update?

Oct 3, 2010

I am putting together a small database for recording stock movement.I have a table which will hold

StockID
StockItem
QtyInStrock

I want the user to enter in a textbox the number required from stock then do the subtraction before updating the QtyInStockWhat is the best approach for doing this.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved