{"id":225,"date":"2014-03-27T21:47:59","date_gmt":"2014-03-28T02:47:59","guid":{"rendered":"\/\/www.beauchamp.me\/techno\/?p=225"},"modified":"2014-03-27T21:47:59","modified_gmt":"2014-03-28T02:47:59","slug":"asp-net-mvc-5-redirecting-to-accountlogin","status":"publish","type":"post","link":"https:\/\/www.beauchamp.me\/techno\/blog\/2014\/03\/27\/asp-net-mvc-5-redirecting-to-accountlogin\/","title":{"rendered":"ASP.Net MVC 5 redirecting to \/Account\/Login"},"content":{"rendered":"<p>I recently upgraded an ASP.Net project from MVC 3 to MVC 5, but wanted to keep our old login mechanism. However, when trying to access a restricted page, I was always redirected to\u00a0\/Account\/Login instead of\u00a0\/Account\/LogOn. I had already met that problem with MVC 3 and thus I had added the following line in my Web.config file:<\/p>\n<pre class=\"brush:xml\">    &lt;add key=\"LoginUrl\" value=\"~\/Account\/LogOn\" \/&gt;<\/pre>\n<p><span style=\"line-height: 1.5em;\">I researched the matter and added some more stuff in the Web.config file according to the suggestions I found on stackoverflow.com and other forums:<\/span><\/p>\n<pre class=\"brush:xml\">    &lt;add key=\"PreserveLoginUrl\" value=\"true\" \/&gt;\r\n    &lt;add key=\"autoFormsAuthentication\" value=\"false\" \/&gt;\r\n    &lt;add key=\"enableSimpleMembership\" value=\"false\" \/&gt;<\/pre>\n<p><span style=\"line-height: 1.5em;\">and\u00a0<\/span><\/p>\n<pre class=\"brush:xml\">    &lt;authentication mode=\"Forms\"&gt;\r\n      &lt;forms loginUrl=\"~\/Account\/LogOn\" timeout=\"2880\" \/&gt;\r\n      &lt;!--&lt;forms loginUrl=\"~\/SGAccount\/LogOn\" timeout=\"2880\"\/&gt;--&gt;\r\n    &lt;\/authentication&gt;<\/pre>\n<p><span style=\"line-height: 1.5em;\">However, all this did not help. I finally found the culprit by searching for &#8220;Login&#8221; in my source code. I found this in App_Start\\Startup.Auth.cs:<\/span><\/p>\n<pre class=\"brush:csharp\">app.UseCookieAuthentication(new CookieAuthenticationOptions\r\n            {\r\n                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,\r\n                LoginPath = new PathString(\"\/Account\/Login\")\r\n            });<\/pre>\n<p>I fixed the issue by replacing &#8220;\/Account\/Login&#8221; with &#8220;\/Account\/LogOn&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently upgraded an ASP.Net project from MVC 3 to MVC 5, but wanted to keep our old login mechanism. However, when trying to access a restricted page, I was always redirected to\u00a0\/Account\/Login instead of\u00a0\/Account\/LogOn. I had already met that problem with MVC 3 and thus I had added the following line in my Web.config [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[13],"tags":[],"class_list":["post-225","post","type-post","status-publish","format-standard","hentry","category-asp-net-mvc"],"_links":{"self":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts\/225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/comments?post=225"}],"version-history":[{"count":2,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts\/225\/revisions"}],"predecessor-version":[{"id":227,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/posts\/225\/revisions\/227"}],"wp:attachment":[{"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/media?parent=225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/categories?post=225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.beauchamp.me\/techno\/wp-json\/wp\/v2\/tags?post=225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}