0

ASP.NETMVCプログラミングは初めてです。私のサイトには、現在のページの終わりに応じて、署名されていないすべてのユーザーをフォルダー\content\にあるページにリダイレクトする次のコードがあります。ユーザーがすでにこのページにリダイレクトされている場合にリダイレクトを行わないようにするには、このコードを変更するにはどうすればよいですか?

using System.Globalization;
using System.Web;
using System.Web.Mvc;

namespace MYSITE.Web.Infrastructure
{
    public class CategoryRedirectAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (((ViewResult)filterContext.Result).ViewName.StartsWith("ProductList", true, CultureInfo.InvariantCulture))
                {
                    var categoryProductPath = filterContext.RouteData.Values["categoryProductPath"].ToString().Split('/');
                    if (categoryProductPath.Length > 0)
                    {
                        HttpContext.Current.Response.Redirect("/Content/" + categoryProductPath[categoryProductPath.Length - 1]);
                    }
                }
            }
        }
    }
}
4

1 に答える 1

0

あなたは自分の人生を難しくしています。ロールベースのFormsAuthenticationを使用して、ユーザーを識別し、コントローラーまたはアクションメソッドの[Authorize]属性を使用して、誰が何を実行できるかを制御できます。

うまくいけば、これがお役に立てば幸いです:http: //msdn.microsoft.com/en-us/library/ff398049 (v=vs.100).aspx

于 2012-11-28T22:16:25.393 に答える