开发者

Problem Redirecting From MasterPage in Asp.net mvc

开发者 https://www.devze.com 2023-01-03 18:19 出处:网络
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() func

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

精彩评论

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