我在AccountController.cs中使用了这些方法:
public ActionResult DomainLogin(string returnUrl)
{
}
public string Loginss(LoginModel model, string returnUrl)
{
}
我的问题是登录后我有重定向方法到索引页面 . 在关闭并使用粘贴的URL重新打开浏览器后尝试复制URL Home/Index
时,我被重定向到 Account/Login
页面,并且在浏览器关闭时调用 public ActionResult DomainLogin(string returnUrl) {}
.
这是RouteConfig.cs代码:
public static void RegisterRoutes(RouteCollection routes){HttpContext ctx = HttpContext.Current; if(ctx.Session == null){routes.IgnoreRoute(“ .axd / {* pathInfo}”);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
}
else
{
if (ctx.Session != null)
{
if (ctx.Session.IsNewSession)
{
string sessionCookie = ctx.Request.Headers["Cookie"];
//if ((sessionCookie != null) || (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
if (sessionCookie != null)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Home_Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
}
}
的Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
GlobalFilters.Filters.Add(new AjaxErrorHandlerAttribute());
new Bootstrap().Configure(filePathToPoints:
string.Concat(HttpContext.Current.Server.MapPath("~"), @"App_Data\Points.csv"));
}
static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
void Session_End(object sender, EventArgs e)
{
if (Session["usernames"] != null)
{
string user = (string)Session["usernames"];
UsersContext userDetails = new UsersContext();
UserProfile data = userDetails.UserProfiles.Where(m => m.UserName == user).FirstOrDefault();
if (data != null)
{
data.Preference = "NoLog";
data.Logged = false;
}
userDetails.SaveChanges();
}
}
}