Search code examples
c#asp.net-mvcvisual-studio-2010asp.net-mvc-4sql-server-2014

Why my app opens empty page and doesn't go to any redirect link after route page?


Why my app opens empty page and doesn't go to any redirect link after route page ?? I work on C# , MVC , Visual studio 2010

this is my login action:

[HttpGet]
    [AllowAnonymous]
    public ActionResult Login()
    {
        return View();
    }

    [HttpPost]
    [AllowAnonymous]
    public ActionResult Login(string name, string psw)
    {
        if ((Membership.ValidateUser(name, psw)) == true)
        {
            FormsAuthentication.SetAuthCookie(name, false);
            if ((Roles.IsUserInRole(name, "Admin")) == true)
            {
                return this.RedirectToAction("AboutDetails_Admin", "mytask");

            }
            else if ((Roles.IsUserInRole(name, "People")) == true)
            {
                return this.RedirectToAction("TMembersDetails_Admin", "mytask");
            }
            else return View();
        }
        else return this.RedirectToAction("Register", "Default");
    }

and this is the login view:

 @{
  ViewBag.Title = "Login";
  Layout = "~/Views/_LayoutPage1.cshtml";
 }

 <h2>Login</h2>

 <form action="/Default/Login" method="post">
  <label>Full Name:</label><input type="text" name="name" /><br />

 <label>Password:</label><input type="text" name="psw" /><br />

 <input type="submit" />


 </form>

this is my web.config :

enter code here

<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor"      type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,   System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral,   PublicKeyToken=31BF3856AD364E35">
  <section name="host"   type="System.Web.WebPages.Razor.Configuration.HostSection,   System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
   </sectionGroup>
   </configSections>

 <system.web.webPages.razor>
 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,   Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
   <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="ttt" />
  </namespaces>
</pages>
</system.web.webPages.razor>

<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>

<system.webServer>
<handlers>
  <remove name="BlockViewHandler"/>
  <add name="BlockViewHandler" path="*" verb="*"   preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
  </handlers>
  </system.webServer>

  <system.web>
  <compilation>
  <assemblies>
    <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral,   PublicKeyToken=31BF3856AD364E35" />
   </assemblies>
  </compilation>
  </system.web>
  </configuration>

and this is my route:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace ttt
{
public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "",
            defaults: new { controller = "Default", action = "Index", 
                 id = UrlParameter.Optional }
        );
    }
   }
  }

what can I do to make my index page redirect to the login page and not open empty page with http://localhost:1889/Default/Login


Solution

  • I found the mistake , in the first in visual studio 2015 when I choosed new project It make the the project Authentication : individual by default , so it resultd empty pages when project run .. when I change authentication (in the first) to No authentication so it works now.