【发布时间】:2020-06-11 23:27:40
【问题描述】:
如何在 ASPX 项目中允许这个 MVC 页面匿名?
在传统的 ASP.NET 项目(aspx 页面)中,有一些 MVC 页面在框架内共存和工作。我最近添加了一个 MVC 控制器和 forgotpassword.cshtml 页面,该页面仅在我登录时工作。控制器具有允许匿名属性,但在此项目中不支持此属性,因为项目中仅存在 MVC 框架的一部分。我在应用程序开始请求中设置了“Context.Response.SuppressFormsAuthenticationRedirect”,这有助于重新引导回登录,但我收到了未经授权的错误。
错误:
Access is denied.
Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3535.0
AccountController.cs
[Authorize]
public class AccountController : SessionReadController
{
public AccountController(IUserSecurityService userSecurityService, ILogger logger)
: base()
{
_logger = logger;
}
[AllowAnonymous]
public ActionResult ForgotPassword()
{
return View();
}
}
Global.asax.cs
private void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.Path.Contains("forgotpassword"))
{
Context.Response.SuppressFormsAuthenticationRedirect = true;
}
}
【问题讨论】:
标签: c# asp.net asp.net-mvc