2012-03-16 11 views

cevap

5

iki yolu:

1 - onlar kaydedilir eğer sayfasından kullanıcıyı yönlendirir Custom Action Filter

public class RedirectAuthenticatedRequests : ActionFilterAttribute 
{ 
    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     if(filterContext.HttpContext.Request.IsAuthenticated) { 
      filterContext.Result = new RedirectToRouteResult(
       new RouteValueDictionary(new { 
         controller = "SomeController", 
         action = "SomeAction" 
       } 
      )); 
     } 

     base.OnActionExecuting(filterContext); 
    } 
} 

2 - basit. Kullanıcı içeriyorsa, login eylem yöntemini kontrol edin.

if(Request.IsAuthenticated) return RedirectToAction("SomeOtherView"); 
+0

gerçekten bir [AuthorizeAttribute] türetilmiş Nitelik oluşturun. – Rhapsody

+0

@Rhapsody, bu Özniteliğe sahip olmanın adımları nelerdir? – updev

+0

@Xander demek ActionFilter on Global.aspx? – updev

5

(giriş/kayıt) kullanıcı kimlik doğrulaması durumunda ve istediğiniz sayfaya yönlendirecek ise: Oturum sayfası için böyle

Something () Register aynı kural geçerlidir: User.Identity.IsAuthenticated özelliğini kontrol etmek ve uygun şekilde yönlendirin olabilir

// 
// GET: /Login/Index 
public ActionResult Index() 
{ 
    if(User.Identity.IsAuthenticated){ 
      //redirect to some other page 
      return RedirectToRoute("Home", "Index"); 
    } 

    return View(); 
} 
0

. "Kafamın üst kapalı"

İlgili konular