You must Sign In to post a response.
  • Category: ASP.Net MVC

    Can any one tell how to support session in webapi controller

    Hi,
    i am dotnet developer,i am using html page with anjular js,web api controls for data retriving,
    my problem is I am using session["username"] in the login controller,after login succcess,i am navigating to Home Controller,then my session is null
    in home controller,
    can any one tell how to support session in webapi controller
  • #761326
    Hi

    You can try this code


    [SessionState(System.Web.SessionState.SessionStateBehavior.Default)]
    public ActionResult Index()
    {
    Session["Easy"]="Welcome";
    ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

    return View();
    }

    [SessionState(System.Web.SessionState.SessionStateBehavior.Disabled)]
    public ActionResult Index()
    {
    Session["Easy"]="Welcome";
    ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

    return View();
    }

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761328
    Hai Ramana,
    As we know that Web API is ReSTful web service where each request is new. So it is difficult to maintain the session state here as with the new Web Http request. But you can make it session enabled, by creating a class which will be used for each request and keep that data for you.
    Below is the link which can be followed to maintain session in case of each http request:

    http://www.strathweb.com/2012/11/adding-session-support-to-asp-net-web-api/

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #761330
    actually i am creating session in webapi control,that is in one controll and i am accessing session in mvc controller that is another project,can any one help pls


Sign In to post your comments