Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    ASP.NET


Advertisements:










MVC :: Create And Set Value Of Session In Controller?


how I can create and set value of session in controller and get value this session because I can't find good tutorial about that in asp.net mvc :/


View 4 Replies (Posted: Jul 01, 2009 11:19 AM)

Sponsored Links:

Related Forum Messages For ASP.NET category:
MVC :: Session Vs TempData / How To Persist Values From Controller To Controller
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?

Posted: May 30, 2010 12:54 AM

View 10 Replies!   View Related
Can Create A Controller With The Standard List, Edit, Create And Delete Methods
I'm an orthodox Webforms man and have decided to give MVC and LINQ a go for a small procurement back-office app I'm building for my company and have come unstuck with implementing a parametrisedsearch. Letsketch the scenario for you...I have an entity model in with 3 table in, I have created a controller with the standard List, Edit, Create and Delete methods. I created a List view by right-clicking in the index method and selecting "Create View" from the menu, the view works perfectly
and populates the grid with data.

Posted: Dec 23, 2009 03:16 PM

View 5 Replies!   View Related
MVC :: Access The Session On The Controller?
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?

Posted: Jan 30, 2010 12:34 AM

View 4 Replies!   View Related
MVC ::Session Variables Called From The Owning Controller?
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?

Posted: Feb 19, 2011 08:47 AM

View 4 Replies!   View Related
State Management :: Differentiate Between New Session Create For New Website Visit Or Session Expired
I have a problem by getting session which created for new site visit or session expired.

Posted: Mar 02, 2011 07:29 AM

View 3 Replies!   View Related
MVC :: Access Session In Controller Method Called Via Reflection?
once the page gets loaded i am storing dictionary<string,string> object in to session.Once the form gets submitted, I tried to access session in controller's action method which is called from base controller class through reflection. But here Session is null, and nothing stored in it.

Detailed description is

I have class called BaseController, which works as base class for all Controllers.

public class BaseController
{
public ActionResult UpdateWorkItem()
{
Type controllerType =

[Code]....

Now after this when The Page gets submitted BaseController's UpdateWorkItem action gets execeuted.This action then internally calls PROPERTYController >UpdateStatus action via reflection.

If ssession is not possible to use then what is alternative way I can store values during roudtrick of form

Posted: Sep 21, 2009 07:06 AM

View 1 Replies!   View Related
Implement Cross-session Data Controller Class?
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.

Posted: Feb 24 at 7:31

View 2 Replies!   View Related
Create A Copy Of An Object In Session To Update Without Updating Session?
I am confused about how to reference objects in session, how to update, and copy.

if I create
MyObject obj = new Object ();
then
Session["object"] = obj;
MyObject temp = (MyObject)Session["object"];

If i change something on temp, will the object in session be updated? do i need to follow changes with Session["object"] = temp?

Posted: Jul 20 10 at 14:49

View 2 Replies!   View Related
MVC :: Access HTTPContext And Session From Custom Base Controller Class?
I built a base controller classinheritsfrom 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.

Posted: Jan 13, 2010 03:12 PM

View 3 Replies!   View Related
C# - Using Grasp Controller With MVC Controller - How To Make An Object Always Visible For A Controller
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.

Posted: Dec 28 10 at 8:12

View 1 Replies!   View Related
MVC :: Calling Controller Action Using Jquery Post Ajax Call Abondons Session?
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.

Posted: Apr 09, 2010 10:35 AM

View 5 Replies!   View Related
MVC :: Create Action Url From Controller?
I need to create an absolute Url to an action from within one of my controller actions. How can I go about doing this?

The scenario here is for email. I need to generate a link that will go into an email pointing back at a specific action URL on the site. I can't hard code anything because this code is used on multiple sites. Is this possible?

Posted: Jul 08, 2009 09:37 PM

View 2 Replies!   View Related
MVC :: How To Create Class In Controller
I am using vs 2010, mvc, linq to sqlMy Model is .dbmliletbl_teacher,tbl_class,tbl_subject etc are involvedI write code in my controller for table join.

[Code]....

Posted: Sep 18, 2010 11:57 AM

View 5 Replies!   View Related
MVC :: Controller Method For Create Not Working
I'm very new to MVC so this is a simple issue, just can't seem to find any information on why it's happening so turning to the forums. Edit works, delete sort of works (that's another issue in itself), and details works, but create causes an issue. I've debugged the form being passed in and it's always null with default values. It's almost identical code to my edit so I'm not sure why edit works and create won't. I'd show code for the view but since it's working for edit I'm currently ruling that out as the problem. "Colleges" in this populates a dropdown in the view.Here's the code:

[Code]....

Posted: Oct 27, 2010 05:49 PM

View 6 Replies!   View Related
MVC :: To Create Controller In .NET Based On Model Like In Symfony ?
In ASP.NET MVC I can generate basic views for example Create / Edit based on some model. Is it possible to generate controller with basic code for actions to create / edit rows in database ? In Symfony php framework it is possible. In ASP.NET MVC actions for create / edit are almost "empty" - I must write code for create / edit by myself. Is other option ?

Posted: Jul 18, 2009 11:00 AM

View 2 Replies!   View Related
MVC :: How To Create List Of Custom Object In Controller
In my controller I fetch a list of object 'object1' which has two fields field1 & field2.Now I have a model model1 which has two fields fieldsX & fieldY.fieldX = field1fieldY = dosomething(field2 also have a view model ViewModel1 which has a single fieldpublic List<model1> model2I need to send model2 to my view

Posted: Jan 02, 2011 06:14 PM

View 4 Replies!   View Related
MVC :: Create A Link In A Webform To Controller-View?
I want tolink to a MVCView from my code-behind in a Webform, but I can't figure out how to do it and I have googled for an eternity :(

Posted: May 25, 2010 09:21 AM

View 3 Replies!   View Related
MVC :: Create A Class Library Contains A Controller Based On Its Module?
In My Project I want to Create a Class Library Contains a Controller based on its module, Example : Class.Controllers.Album,Class.Controller.Artist

in this Class Library I wrote two Controllers AlbumController.cs, ArtistController.cs.When I add this to Main Project Contains Views,

Posted: Feb 22, 2011 03:00 AM

View 1 Replies!   View Related
Custom Server Controls :: How To Create A Video Controller Similar To That In Youtube
how to create a video controller similar to that in youtube? is it possible to make either a custom control or a user control? This should show the available videos and the user can click and play the desired video.

Posted: Jun 29, 2009 11:00 AM

View 3 Replies!   View Related
MVC :: MVC3 - An Error Occurred When Trying To Create A Controller Of Type 'SignInMVC3.MenuController'?
I'mjust started with MVC3 and have the following error when I want to run my application :

An error occurred when trying to create a controller of type 'SignInMVC3.MenuController'. Make sure that the controller has a parameterless public constructor.

This is my MenuModel code

[Code]....

This is my MenuController

[Code]....

This is the code of my LoadMenu.asx (view usercontrol)

[Code]....

And this code is in the site.master page where I want to render the menu

[Code]....

Posted: Jan 18, 2011 09:23 AM

View 7 Replies!   View Related
MVC :: How To Create A Controller And View With Data Coming From Seprate Tables Associated With Foreign Key
I am using Entity Frameowrk as the ORM. I am new to MVC and trying to develop a samll module as a learning project.

Now I am stuck with an issue for which I can't seem to find out answer on web. The issue is :

I have two tables mapped as entities - Tenant_Definition and Contact

Tenant_Definition { Tenant_ID , Desc, Contact_ID}

Contact {Contact_ID, Company_Name,Company_Address,Person_Name, Person_Phone_Mobile}

My View has to present a form that shows Tenant Desc and Contact related fields. The index view works fine and shows the desired values.

But, the create view isn't working out. In the create view, i am planning to do -

1. creating a new contact entity instance and saving it in db

2. Then creating a new tenant entity instance using the new contact_id and save it to the DB.

However, the code doesn't seem to be inserting any value inside Contacts table. It inserts null value.Below is the code snippet of my Create Controller -

[HttpPost]
public ActionResult Create(FormCollection collection)
{
var newContact = new Contact();[code]....

Posted: Mar 08, 2011 10:20 PM

View 6 Replies!   View Related
MVC :: Out Of The Box MVC2 Controller / Delete Controller Is Refusing To Return Any Class Information
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

Posted: Nov 06, 2010 05:47 PM

View 4 Replies!   View Related
Create A Session ID?
I am using Visual Basic in coding. how I can generate a sesion Id for a user that logged-in his account and store it in a sesion variable. I am also confused that if I were to use sesions, do i need to modify the web.config file and what are the codes do i need in order to check the status of a sesion.

Posted: Dec 27, 2009 12:01 PM

View 5 Replies!   View Related
MVC :: Pass Parameter From Controller To View And Back To Another Controller?
I have a simple model where aPerson has Gifts. I havea view which is a list ofGifts belonging to one Person.

My problem is with theCreate action for a new Gift. I want it to default to the PersonIDthat we are alreadyviewing the list ofGifts 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?

Posted: Aug 16, 2010 02:53 PM

View 2 Replies!   View Related
MVC :: How To Create Session Timed Out
i have two pages a1.aspx a2.aspx....

if i do nothing in a1.aspx for 1minute...it should redirect me to a2.aspx...how to do this in mvc...or javascript

Posted: Nov 07, 2010 11:36 AM

View 6 Replies!   View Related
MVC :: Create A Partial View And A Controller That Will Feed Data Tothe View?
Can i create a partial view and a controller that will feed data tothe view, and if irender that partial ina Master page, the Data will show on whateverURL i am?

Or is there another way of showing content fromdatabase onevery page(view)?

Posted: Jan 27, 2010 07:18 PM

View 2 Replies!   View Related
MVC :: Get The Current Action / Controller Name In A Controller Or Class?
How do you get the current action / controller name in a controller or class?

i can't show it in my view but that's not what i want.

Posted: Mar 14, 2011 01:07 PM

View 1 Replies!   View Related
Trying To Create Session DataTable In A Class?
I built a sample Shopping Cart page that had an internal datatable holding the information for the gridview. However, when I was done the example, I realized I had a problem because what I really needed to be able to do was to add items from my products.aspx page to the datatable and then display the itemsfrom the datatable on my Shopping cart page.So, I am now trying to figure out how to migrate my code for the datatable into a classs. From the App_Code folder I added a new class. I opened the new class up in ClassView. I right clicked ClassView and choose add Method.

To start I am migrating a subroutine from my example shopping cart page called public void makeCart() to a class method called CreateShoppingCartDataTable.Here is the code from makeCart()

[Code]....

This is what I put into my new class - CreateShoppingCartDataTable

[Code]....

Right away I see that I am getting an error on Session["UBOcart]" = UBOcartTable

Questions:

1.Do I just leave the last line out ... Session["UBOcart"] = UBOcartTable;

2. I have never built a class before, (I have always used aSQL2005 database and then used objectdatasource to read write to it), so do I need the "= new DataTable("UBOcart")" in line 1 or can I just go " = new DataTable()".

3. Depending on the answer to Question #2 ... When I do my page load event of Products.aspx or Shopping.aspx. Do I create or check for the DataTable existance something like this...

[Code]....

Posted: Jul 21, 2009 02:10 PM

View 4 Replies!   View Related
How To Create A New Session On The Page If It Has Timed Out
is there a way to create a new session if it has timed out ? in mobile appication developing using asp.net?getting this error:the page requires session state that is no longer available. either the session has expired, the client did not send a valid session cookie, or the session state history size is too small. try increasing the history size or session expiry limit

<sessionState cookieless="UseCookies" cookieName="Mobile_Session" regenerateExpiredSessionId="true">
</sessionState>

Posted: Mar 15 at 17:07

View 2 Replies!   View Related
Web Forms :: Create The Sql Query On Session End?
I've created the temporary table, where I store logged users.

When user press logout button via sql I delete the logged user from this table. Problem appear only when user close web browser.

How to use sql via session end. Below sql to delete user from temp table:

LblUserIDValue.Text = HttpContext.Current.User.Identity.Name.ToString <-system takes logged user(web auth)

deleteSQL = "delete from temp where loginuser= @user"
cmd.Parameters.AddWithValue("@user", LblUserIDValue.Text)

Posted: Jun 16, 2010 01:49 PM

View 11 Replies!   View Related
Create A Session Base On A Hyperlink?
i would like to know if i could create a session base on an hyperlink i do not want to pass param to the page i wanted to create a session base on a hyper link comming from a gridview.

this page would normaly populated when the user logon however i wanted the some oneelse to access this page like the orginal user would except that he would not log on but the page would see the session as if it was the user. click event i am using aspx:hyperl

< temTemplate
>
<asp:HyperLink
ID="HyperLink1"
runat="server"
Visible='<%# Not(Eval("Return")) %>'
Enabled
=
'<%# Not(Eval("Return")) %>'
NavigateUrl='<%# Eval("PN", "~/test/htest.aspx?P={0}" ) %>'
>SR</asp:HyperLink></ItemTemplate>

i want to create a session allone with it

Posted: Aug 12, 2010 08:19 PM

View 3 Replies!   View Related
Create A Session For A Field In A Datalist?
i want to create a session for a field in a datalist. I am using the following datalist control:-

If i had , then how can i make a session of this in my code behind..? For example Session[""] = Container.DataItem, "Message"

Posted: May 20, 2009 10:47 PM

View 3 Replies!   View Related
MVC :: Create Session Variable At Logon?
I'm building an application using MVC3 RC and I'm trying to add a session variable as soon as anyone logs on. The variable is an int which is retrieved from adatabase usingUser.Identity.Name toretrieve the relevant database record.

I'm using the MS AccountController and tried adding the session variable immediately after the line:

FormsService.SignIn(model.UserName, model.RememberMe);

Although this is the point at which the logon is validated the User.Identity.Name is still showing as null when I try to get it immediately after.

Does anyone know when User.Identity.Name is actually populated in the session and how I can intervene to grab it at that point?

Posted: Dec 03, 2010 01:07 AM

View 2 Replies!   View Related
How To Create Checkbox To Remmber Session Until Userlogout
How to create remember me checkbox to remmber session until userlogout ..?if user directly close their browser without logout then next tiem they open browser its session will be maintained as it is till they logout from session .

Posted: Jan 21 at 14:54

View 2 Replies!   View Related
Security :: Create Login Page Using Session
how to create login page using session

Posted: Jan 20, 2011 04:09 PM

View 6 Replies!   View Related
Mobiles :: Create A New Session On The Page If It Has Timed Out?
is there a way to create a new session if it has timed out ?

Posted: Mar 15, 2011 05:05 PM

View 3 Replies!   View Related
Create A Session Id When A New Browser Window Opens?
I need to create a session id when a new browser window opens.

with that session id I need to create a table in run time.

Posted: Feb 16, 2009 11:02 AM

View 6 Replies!   View Related
VS 2005 - How To Create A Session Long Variable Without Using Sessions
So im trying to create a session long variable, without using sessions. Basically what i have setup is a class to inherit instead of System.Web.UI.Page... Anyway on MyBaseClass I have

Code:

Inherits System.Web.UI.Page
Public CurrentUser As New WebsiteClass.CurrentUser
And i call

Code:

Public Sub ValidateUser()
Dim Currentuser As New CurrentUser("New User", "FirstName", "LastName", "Email", "ID")
End Sub

Is there another way i can create currentuser to last through every page without having to say NEW WebsiteClass.CurrentUser?

If i don't use new in the 1st code above i get a null reference exception. If i do use new in the 1st code above the CurrentUser.Email comes up empty.

Posted: Jul 19th, 2009, 09:38 AM

View 12 Replies!   View Related
Security :: Create Session On Login And Redirect From Other Applications
I have createdcustom a MembershipProvider, SessionIDManager, and SessionStateStore since I need to use custom legacy sessions and logins.. When the Application is ran, it runs the GetSessionID in the SessionIDManager(which is correct) The problem then is if there is no session meaning the GetSessionID method returns null, it tries to create a new session using CreateSessionID.. I want it to redirect to the login application(another application). We only create and store session information for logged in users and the "session id numbers" come from a file that is pre-populated with "session id numbers"(I didnt design this and its out of my control).. So its not feasable to give everyone who visits the site one of the "session id" numbers. I also need for users with an "invalid" session(when checked through Validate()) to be redirected to the login page.

Posted: Sep 29, 2010 08:48 PM

View 4 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved