Home Using Session-variable to Redirect
Reply: 0

Using Session-variable to Redirect

user1366
1#
user1366 Published in April 22, 2018, 4:53 am

i have a website (products) where i call a function from my model. in this function i declare a session-variable:

HttpContext.Current.Session["name"] = "x";

now in the site1-controller i try to work with this session-variable and try to redirect to site 2 if the session-variable is "x":

    public ActionResult Products() 
    { 

        if(System.Web.HttpContext.Current.Session["name"]!=null)
        {
            if (System.Web.HttpContext.Current.Session["name"].ToString() == "x")
            {
                return RedirectToAction( "Index", "Site2");
            }
            else {
            return View(); }

        }
        else
        {
        return View();
        }

    }

here is the controller of site2:

    public ActionResult Index()
    {
        return View();
    }

but its not working. the products-site still loads, but with the layout of site2.

ive also tried to work with the session-variable on the products-site:

if (Session["role"] != null)
{
if (Session["role"].ToString() == "x")
{
    @Html.Action(actionName: "Index", controllerName: "Site2");
}
}

but still the same problem. can anyone point out to me what thats about and what i can do to solve this? thanks.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299142 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO