开发者

Problem Redirecting From MasterPage in Asp.net mvc

I have a masterpage on which ill check for a condition if condition is true i want to redirect it to a particular view. how can i do this because on masterpage either view() or RedirectToAction() function a开发者_JAVA技巧re available. My condition is

if(Session["Name"]==null)
//redirect to login
else
//work as usual


you would typically do it in your controller...

alternatively if it is for authentication you can use:

FormsAuthentication.RedirectToLoginPage()


You can use the good old <% this.Response.Redirect("/controller/action"); %> Be aware that redirection logic have to be in your controller, not your view.


A nice way to redirect from masterpage is

 <% if(Session["abcd"]==null) {
 Response.Redirect(Url.Action("actionname","controllername")
 } %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜