c# - 避免在部分 View 中授权

标签 c# .net asp.net-mvc security authorize

这是我的homecontroller的代码。

    public class HomeController : Controller
    {
          [AllowAnonymous]
          public  PartialViewResult FB_InviteFriends()
          {
               return PartialView("~/Views/ListContats/_fbinvite.cshtml");
          } 
          [Authorize]
          public ActionResult YourZone()
          {
               return View();
          }
    }

我想使用以下网址访问 FB_InviteFriends() 方法 public/unAuthorized 用户: /Home/yourzone/FB_InviteFriends 但由于 [Authorize] 属性,它会将我重定向到登录页面。 现在我的问题是,有什么方法可以避免授权,而无需删除 [Authorize] 属性,因为我在 yourzone 上需要它。任何 global.asax 过滤任何可能有帮助的路由过滤器。

最佳答案

为此路径添加授权异常(exception),例如

  <location path="Home/yourzone/FB_InviteFriends">    
    <system.webServer>
      <security>
        <authentication>
          <windowsAuthentication enabled="false" />
          <anonymousAuthentication enabled="true" />
        </authentication>
      </security>
    </system.webServer>
  </location>

您可能需要根据您在网站上使用的身份验证进行调整。

关于c# - 避免在部分 View 中授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22013268/

相关文章:

c# - winform 中的弹出窗口

c# - 在 C# 中查询 Access '07 数据库的问题

c# - Unity3D:让玩家使用 ParticleSystem 和 OnCollisionEnter 点亮手电筒?

c# - 如何从字典值中获取 ObservableCollection

c# - 开源项目学习asp.net mvc 3

c# - C# 和 java 中的 volatile 有什么区别?

c# - 在Youtube Downloader .dll中返回值的最佳方法是什么?

c# - 当 AutoCheck 属性在 C# 中设置为 false 时,手动选中和取消选中 RadioButton 的正确方法是什么?

c# - 如何在 MVC 4 中显示来自路径的图像?

asp.net-mvc - jQuery 自动完成完全没有响应