.Net MVC应用程序始终重定向到公共页面的登录名

时间:2019-06-03 20:33:54

标签: asp.net .net asp.net-mvc asp.net-mvc-4

环境:.Net 4.6.2,MVC 5.2.4,VS2017。向我的现有Web应用程序添加公共/默认页面并用[AllowAnonymous]装饰控制器类后,在本地调试环境中,我的应用程序始终显示网址为localhost:12345的登录页面。以下是我所做的事情,我想念的是什么? TIA

  1. 路由到RouteConfig.cs中的默认页面

    公共静态无效RegisterRoutes(RouteCollection路由)     {         route.IgnoreRoute(“ {resource} .axd / {* pathInfo}”);

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "mydomain.web.Controllers" }
        );
    }
    

    }

    1. Controllers / HomeController
    [AllowAnonymous]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
           return View();
        }
    }
    
  2. 检查IIS Express配置

         <site name="mydomain.web" id="2">
                    <application path="/" applicationPool="Clr4IntegratedAppPool">
                        <virtualDirectory path="/" physicalPath="E:\mydomain.web" />
                    </application>
                    <bindings>
                        <binding protocol="http" bindingInformation="*:52792:localhost" />
                    </bindings>
                </site>
  1. 我的Views / Home / Index.cshtml

@ {布局= null;}

   <html><head><meta name="viewport" content="width=device-width" /><title>Index</title></head><body><div></div></body></html>
  1. web.config
<authentication mode="Forms">
     <forms loginUrl="~/Account/Login" name="AuthClientUser"
           timeout="60" slidingExpiration="true" cookieless="UseCookies" 
           path="/">
     </forms>
</authentication>
  1. http流量

请求:http://localhost:12345 响应:找到302,位置:/ Account / Login?ReturnUrl =%2f

2 个答案:

答案 0 :(得分:0)

请不要介意。 web.config的授权部分拒绝了我忘记的所有匿名用户。

答案 1 :(得分:0)

可能是您的web.config中的Forms标记导致您的应用程序调用URL“〜/ Account / Login”,因为它认为您的用户未通过身份验证,但控制器中没有此类Route。

如果需要,尝试将配置中的LoginUrl格式更改为现有的索引路由“〜/ Index”,或创建新的Action来处理该路由。

相关问题