Categories

None

The query posted can be seen here http://stackoverflow.com/questions/1672007/user-roles-why-not-store-in-session

My obvious question is that why do you want to store a users role in session ?

Here is my answer to your query, how this helps. I have attached a small demo application for you to take a look at and understand my points. When you open this project in visual studio, click on the project tab on the top and select asp.net configuration. From the page that will show up you can do the user administration stuff.

You need to store the roles of a user in some secure manner ? The answer to this question is that there is no need for you to worry about storing the role for any user, when we have the asp.net membership, profiles and roles framework to help us out on this. All you need to do is create a role in the aspnet database and assign that role to the user.

Next you want to store two string in some secure manner. I suggest you user profile for storing user specific information. This way you have the information available to you where ever you want from the profilecommon class.

Also please see the attached demo application. Hope this helps.

DemoApplication.rar (3.78 mb)

By default when you run a web application using visual studio the default development web server would fire up for you. In case you want to use the IIS installed on your machine for debugging the web application, you will have to modify the project properties on the web project to point to the IIS server.  See the screen shot below

Now when you will fire up the web application using visual studio it will run using the IIS server installed on your machine rather than using the default development web server.

In a MVC application the member that gets returned to the client and is visible to the application user is the View. As a user interacts with the MVC application and performs some action to post or submit the form to the server, the request is handled by the controller who know which view to return at the end of the cycle. The code for the controller goes something like this

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

 

namespace SampleApplication.Controllers

{

  [HandleError]

  public class HomeController : Controller

  {

    public ActionResult Index()

    {

      ViewData["Message"] = "Welcome to ASP.NET MVC!";

 

      return View();

    }

 

    public ActionResult About()

    {

      return View();

    }

  }

}

 

In the code above the controller returns the Index or the About views depending on the controller method which handled the request. Its not necessary that the Index method returns the Index view and the About method returns the About view. We can explicitly specify which view to return from a given controller. For example in the code below the Test controller method returns the Index view.

namespace SampleApplication.Controllers

{

  [HandleError]

  public class HomeController : Controller

  {

    public ActionResult Index()

    {

      ViewData["Message"] = "Welcome to ASP.NET MVC!";

 

      return View();

    }

 

    public ActionResult About()

    {

      return View();

    }

 

    public ActionResult Test()

    {

      ViewData["Message"] = "Index view return from the Test action .";

      return View("Index");

    }

  }

}

Now the next question that comes to mind is that is View the only thing that we can return from a controller method. The answer is no. There are other things that can be returned by the controller methods, for example


Result returned

Description

ViewResult

Returns html and markup

JsonResult

Retruns a json object

JavascriptResult

Returns a javascript. The content type of the response is set to application/javascript

ContentResult

Returns a user defined content type

FileContentResult

Sends binary contents in the response.

FilePathResult

Sends the content of a file to the response

FileStreamResult

Sends a file stream as binary content in the response.

 

 

SampleApplication.rar (260.62 kb)

Welcome to Bootcamp !

We are a team of experts with industry experience in providing software solutions over a wide range of spectrum. Over the period of time we have practiced and refined our software designing, development and deployment skills. With our strong and exceptionally talented team in US we stand a strong chance to make a mark in the software industry over the coming years.

Bootcamp is a leap forward in cultivating young engineering minds and making them industry ready. In the process of doing so we will continuously be in the process of strengthening our team @Mind Field Software Solutions Pvt Ltd by pouring in the trained talent from Bootcamp. All trainers at Bootcamp are working professionals with vast software experience. Each of our faculty member is equipped with working experience rather than just teaching experience.

 

Mind Field Software Solutions

MindField Software Solutions means We All

A company born out of a collective vision of individuals who enjoy working on the technology bleeding edge. A gathering place for keen minds working in unchartered waters of technology under the gentle guidance and assistance of other experienced minds. MSS stands committed to creative work and ideas.

Innovation, inventions, research, thinking out of the box are a few terms which describe each mind at MSS. Mind fielder’s strive for an experience which changes the ways software is thought of and engineered.

Currently engaged in development tools and products with near future plans of entering the Robotics arena with an emphasis on Home Automation, Wireless and Apple iPhone technology!