这是我的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/