Reputation: 523
I'm working with ASP.net and MVC3 . I need to show a popup or go to the login page When the session get expired. Can any one please tell me How to redirect to login page which is having action name as "index" and the controller name as "Home".
My Code is:
This method is in my model.In this model I have to redirect to login page.
protected Product GetCurrentCorp(HttpContextBase context)
{
if (context.Session != null)
{
var selectedProduct = context.Session["SelectedProduct"];
if (selectedProduct != null)
{
var product= selectedProduct as Product;
return product;
}
}
// Here I need to redirect to index page(login page)
throw new ArgumentException("Product is not set, Cannot Continue.");
}
Upvotes: 2
Views: 21135
Reputation: 4732
This is the self contained action that is showing you examples of redirection to different action or URL.
public ActionResult MyAction()
{
// Use this for action, can also be used to redirect
// to action on different controller by adding parameter
return RedirectToAction("MyActionName");
// Use this for URL
return Redirect("http://example.com/foo/bar");
}
Hope this is of help to you.
Upvotes: 2
Reputation: 22619
Use
Also refer old post ASP.Net MVC Redirect To A Different View
Upvotes: 3
Reputation: 976
You can use RedirectToAction()
return RedirectToAction("ActionName", "ControllerName");
Upvotes: 1
Reputation: 1916
If LoggedOn is your Action and Account is your Controller then you can write your code as:
return RedirectToAction("LoggedOn", "Account");
Hope this will help you.!!!
Upvotes: 4