Необычное поведение в ASP. NET MVC маршрутизации - PullRequest
0 голосов
/ 26 марта 2020

При первой попытке входа в систему пользователь вводит правильные учетные данные, но приложение снова вводит логин, но я перенаправил его на другое действие контроллера. После этого, когда пользователь пытается второй вход в систему, он успешно перенаправляет на панель мониторинга, но на этот раз, когда пользователь нажимает любую ссылку, он снова перенаправляет на вход в систему вместо ожидаемого маршрута. Но с третьей попытки все ссылки доступны. Я не понял, что происходит, пожалуйста, помогите

Настройка маршрутизации

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

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

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

web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
  <connectionStrings>
    <!--<add name="UsersDBCcotext" connectionString="Server=hgws7.win.hostgator.com; User ID=begiqi_adi_; Password=Waleed4444; Integrated Security=false;Initial Catalog=begiqi_adi" providerName="System.Data.SqlClient" />-->
    <!--<add name="UsersDBCcotext" connectionString="Data Source=VAIO\SQLEXPRESS;Integrated Security=true;Initial Catalog=UsersDB4" providerName="System.Data.SqlClient" />-->
    <!--<add name="UsersDBCcotext" connectionString="Server=hgws7.win.hostgator.com; User ID=begiqi_adi_; Password=Waleed4444; Integrated Security=false;Initial Catalog=begiqi_adi" providerName="System.Data.SqlClient" />-->
    <add name="UsersDBCcotext" connectionString="Data Source=DELL;Integrated Security=true;Initial Catalog=UsersDB5" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="false" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Вход в систему Сообщение Функция

[HttpPost]
public ActionResult Login(Users ObjUsers)
{
    var EncryptedPassWord = System.Text.Encoding.UTF8.GetBytes(ObjUsers.Password);
    var UserCheck = db.Users.Where(x => x.Name == ObjUsers.Name && x.UserPassword == EncryptedPassWord ).FirstOrDefault();
    var UserAdmin = db.Admin.Where(x => x.Name == ObjUsers.Name && x.UserPassword == EncryptedPassWord).FirstOrDefault();

    if (UserCheck != null)
    {
        if (UserCheck.IsActive == true)
        {
            var profilerights = db.ProfileRights.Where(x => x.ProfileRightsId == 2).FirstOrDefault();

            if (profilerights != null)
            {
                WebUsersLogs.AccessFeatures = profilerights.GivenRights.Split(',').ToArray();
            }

            WebUsersLogs.UserID = UserCheck.UsersId;
            WebUsersLogs.User = UserCheck;

            return RedirectToAction("DiscussionsDash","User");
        }
        else
        {
            TempData["msge"] = "Your Account has expired";
            TempData["MsgType"] = 0;

            return RedirectToAction("Login");
        }
    }
    else if (UserAdmin != null)
    {
        var profilerights = db.ProfileRights.Where(x => x.ProfileRightsId == 1).FirstOrDefault();

        if (profilerights != null)
        {
            WebUsersLogs.AccessFeatures = profilerights.GivenRights.Split(',').ToArray();
        }

        WebUsersLogs.AdminId = UserAdmin.AdminId;
        WebUsersLogs.Admin = UserAdmin;

        return RedirectToAction("DiscussionsDash", "User");
    }
    else
    {
        TempData["msge"] = "Username or Password is invalid";
        TempData["MsgType"] = 0;

        return RedirectToAction("Login");
    }
}
...