<legend id='Ebcn8'><style id='Ebcn8'><dir id='Ebcn8'><q id='Ebcn8'></q></dir></style></legend>
    1. <small id='Ebcn8'></small><noframes id='Ebcn8'>

    2. <tfoot id='Ebcn8'></tfoot>
        <bdo id='Ebcn8'></bdo><ul id='Ebcn8'></ul>
    3. <i id='Ebcn8'><tr id='Ebcn8'><dt id='Ebcn8'><q id='Ebcn8'><span id='Ebcn8'><b id='Ebcn8'><form id='Ebcn8'><ins id='Ebcn8'></ins><ul id='Ebcn8'></ul><sub id='Ebcn8'></sub></form><legend id='Ebcn8'></legend><bdo id='Ebcn8'><pre id='Ebcn8'><center id='Ebcn8'></center></pre></bdo></b><th id='Ebcn8'></th></span></q></dt></tr></i><div id='Ebcn8'><tfoot id='Ebcn8'></tfoot><dl id='Ebcn8'><fieldset id='Ebcn8'></fieldset></dl></div>

        asp.net mvc 添加到 AUTHORIZE 属性

        asp.net mvc Adding to the AUTHORIZE attribute(asp.net mvc 添加到 AUTHORIZE 属性)

            <tbody id='rlZak'></tbody>
        1. <tfoot id='rlZak'></tfoot>
          <i id='rlZak'><tr id='rlZak'><dt id='rlZak'><q id='rlZak'><span id='rlZak'><b id='rlZak'><form id='rlZak'><ins id='rlZak'></ins><ul id='rlZak'></ul><sub id='rlZak'></sub></form><legend id='rlZak'></legend><bdo id='rlZak'><pre id='rlZak'><center id='rlZak'></center></pre></bdo></b><th id='rlZak'></th></span></q></dt></tr></i><div id='rlZak'><tfoot id='rlZak'></tfoot><dl id='rlZak'><fieldset id='rlZak'></fieldset></dl></div>

            <bdo id='rlZak'></bdo><ul id='rlZak'></ul>

            <small id='rlZak'></small><noframes id='rlZak'>

                  <legend id='rlZak'><style id='rlZak'><dir id='rlZak'><q id='rlZak'></q></dir></style></legend>
                • 本文介绍了asp.net mvc 添加到 AUTHORIZE 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何创建自定义属性来扩展 MVC 中现有的 Authorize 属性?

                  How do I create a custom attribute to extend existing Authorize attribute in MVC?

                  推荐答案

                  从 AuthorizeAttribute 派生你的类.覆盖 OnAuthorization 方法.添加并设置一个 CacheValidationHandler.

                  Derive your class from AuthorizeAttribute. Override the OnAuthorization method. Add and set up a CacheValidationHandler.

                  public void CacheValidationHandler( HttpContext context,
                                                      object data,
                                                      ref HttpValidationStatus validationStatus )
                  {
                      validationStatus = OnCacheAuthorization( new HttpContextWrapper( context ) );
                  }
                  
                  
                  public override void OnAuthorization( AuthorizationContext filterContext )
                  {
                      if (filterContext == null)
                      {
                          throw new ArgumentNullException( "filterContext" );
                      }
                  
                      if (AuthorizeCore( filterContext.HttpContext ))
                      {
                         ... your custom code ...
                         SetCachePolicy( filterContext );
                      }
                      else if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
                      {
                          // auth failed, redirect to login page
                          filterContext.Result = new HttpUnauthorizedResult();
                      }
                      else
                      {
                         ... handle a different case than not authenticated
                      }
                  }
                  
                  
                  protected void SetCachePolicy( AuthorizationContext filterContext )
                   {
                       // ** IMPORTANT **
                       // Since we're performing authorization at the action level, the authorization code runs
                       // after the output caching module. In the worst case this could allow an authorized user
                       // to cause the page to be cached, then an unauthorized user would later be served the
                       // cached page. We work around this by telling proxies not to cache the sensitive page,
                       // then we hook our custom authorization code into the caching mechanism so that we have
                       // the final say on whether a page should be served from the cache.
                       HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;
                       cachePolicy.SetProxyMaxAge( new TimeSpan( 0 ) );
                       cachePolicy.AddValidationCallback( CacheValidationHandler, null /* data */);
                   }
                  

                  这篇关于asp.net mvc 添加到 AUTHORIZE 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                  C# Attributes and their uses(C# 属性及其用途)
                      <tbody id='K1mlb'></tbody>

                        <bdo id='K1mlb'></bdo><ul id='K1mlb'></ul>
                        <i id='K1mlb'><tr id='K1mlb'><dt id='K1mlb'><q id='K1mlb'><span id='K1mlb'><b id='K1mlb'><form id='K1mlb'><ins id='K1mlb'></ins><ul id='K1mlb'></ul><sub id='K1mlb'></sub></form><legend id='K1mlb'></legend><bdo id='K1mlb'><pre id='K1mlb'><center id='K1mlb'></center></pre></bdo></b><th id='K1mlb'></th></span></q></dt></tr></i><div id='K1mlb'><tfoot id='K1mlb'></tfoot><dl id='K1mlb'><fieldset id='K1mlb'></fieldset></dl></div>

                            <small id='K1mlb'></small><noframes id='K1mlb'>

                            <legend id='K1mlb'><style id='K1mlb'><dir id='K1mlb'><q id='K1mlb'></q></dir></style></legend>
                          • <tfoot id='K1mlb'></tfoot>