2009-06-02 14 views
0

私はアカウント管理コントローラを書き込み、別に自分のユーザーのアカウントの削除を処理しなければならないのです。クリアサインアウト後のRequest.IsAuthenticated値()()

[Authorize] 
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Delete(string userName, string confirmButton) 
{ 
    MembershipService.DeleteUser(userName); 

    if (User.Identity.Name.Equals(userName, 
     StringComparison.InvariantCultureIgnoreCase)) 
    { 
     FormsAuth.SignOut(); 

     return View("DeleteSelf"); 
    } 
    else 
     return RedirectToAction("Index"); 
} 

しかし、部分ビューLogOnUserControl.ascxはまだだけを示しRequest.IsAuthenticatedおよびPage.User.Identityの値はFormsAuth.SignOut()の後に設定されているため、DeleteSelfビューを表示している間にユーザー名がログアウトされます。

... 
    { 
     FormsAuth.SignOut(); 

     return RedirectToAction("ShowDeleteSelfMessage"); 
    } 
    ... 

public ActionResult ShowDeleteSelfMessage() 
{ 
    return View("DeleteSelf"); 
} 

他のアイデア:

新しいアクションShowDeleteSelfMessageが問題を解決することができますが、私はこのソリューションを好きではないの追加?ありがとうございました!代わりにreturn View("DeleteSelf")Deleteアクションで

答えて

1

のViewData [ "UserDeleted"]に対処するためにあなたのLogOnUserControl.ascxを変更します。

[Authorize] 
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Delete(string userName, string confirmButton) 
{ 
    MembershipService.DeleteUser(userName); 

    if (User.Identity.Name.Equals(userName, 
     StringComparison.InvariantCultureIgnoreCase)) 
    { 
     FormsAuth.SignOut(); 

     // *** 
     ViewData["UserDeleted"] = true; 
     // *** 

     return View("DeleteSelf"); 
    } 
    else 
     return RedirectToAction("Index"); 
} 

LogOnUserControl.ascx:私が試したし、残念ながら、これはRedirectToActionと同等であるものを学びました

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> 
<% if (Request.IsAuthenticated && !(ViewData["UserDeleted"] ?? false)) { %> 
    Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>! 
    [ <%= Html.ActionLink("Log Off", "LogOff", "Account") %> ] 
<% } else { %> 
    [ <%= Html.ActionLink("Log On", "LogOn", "Account") %> ] 
<% } %> 
0

、私は標準のAccountController.csファイルのソースコードを調べて、二つの方法

public ActionResult ChangePasswordSuccess() 
{ 
    return View("ChangePasswordSuccess"); 
} 

public ActionResult RestorePasswordSuccess() 
{ 
    return View("RestorePasswordSuccess"); 
} 

を発見したこのreturn Redirect("DeleteSelf")

+0

(「DeleteSelf ") –

+0

あなたのOPとそれほど違いはありません、それは返信View(" DeleteSelf ")ですか? –

+0

残念ながら同じです。しかし、今私は、ビューを表示するための別個のアクションを追加することが共通のパターンであると考えています。 –

0

を試してみてください対応するビューのみを表示します。だから私の

public ActionResult ShowDeleteSelfMessage() 
{ 
    return View("DeleteSelf"); 
} 

方法はこのような会社でよく見えます。私は一貫性のために名前を変更する必要があります。

関連する問題