相关疑难解决方法(0)

ASP.NET MVC - 设置自定义IIdentity或IPrincipal

我需要做一些相当简单的事情:在我的ASP.NET MVC应用程序中,我想设置一个自定义IIdentity/IPrincipal.哪个更容易/更合适.我想要扩展默认值,以便我可以调用类似User.Identity.Id和User.Identity.Role.没什么特别的,只是一些额外的属性.

我已经阅读了大量的文章和问题,但我觉得我做得比实际更难.我觉得这很容易.如果用户登录,我想设置自定义IIdentity.所以我想,我将Application_PostAuthenticateRequest在我的global.asax中实现.但是,每次请求都会调用它,并且我不希望在每个请求上调用数据库,这些请求将从数据库请求所有数据并放入自定义IPrincipal对象.这似乎也是非常不必要,缓慢,并且在错误的地方(在那里进行数据库调用)但我可能是错的.或者数据来自何处?

所以我想,每当用户登录时,我都可以在我的会话中添加一些必要的变量,我将其添加到Application_PostAuthenticateRequest事件处理程序中的自定义IIdentity中.但是,我Context.Session在null那里,所以这也不是要走的路.

我已经在这一天工作了一天,我觉得我错过了什么.这不应该太难,对吧?我也对此附带的所有(半)相关内容感到困惑.MembershipProvider,MembershipUser,RoleProvider,ProfileProvider,IPrincipal,IIdentity,FormsAuthentication....我是唯一一个谁发现这一切非常混乱?

如果有人能告诉我一个简单,优雅,高效的解决方案,可以在IIdentity上存储一些额外的数据而不需要额外的模糊...这将是非常棒的!我知道在SO上有类似的问题,但如果我需要的答案就在那里,我一定会忽略.

asp.net asp.net-mvc forms-authentication iprincipal iidentity

638
推荐指数
5
解决办法
21万
查看次数

迁移匿名配置文件的最佳方式

是否存在隐式迁移所有参数的替代方法?或任何其他优点.

来自MSDN:

public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
  ProfileCommon anonymousProfile = Profile.GetProfile(args.AnonymousID);

  Profile.ZipCode = anonymousProfile.ZipCode;
  Profile.CityAndState = anonymousProfile.CityAndState;
  Profile.StockSymbols = anonymousProfile.StockSymbols;

  ////////
  // Delete the anonymous profile. If the anonymous ID is not 
  // needed in the rest of the site, remove the anonymous cookie.

  ProfileManager.DeleteProfile(args.AnonymousID);
  AnonymousIdentificationModule.ClearAnonymousIdentifier(); 

  // Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, true);

}
Run Code Online (Sandbox Code Playgroud)

或者这是最好/唯一的方式?

asp.net profiling anonymous migrate

8
推荐指数
1
解决办法
1592
查看次数

ASP.NET Core MVC 中的匿名标识

在以前的 ASP.NET MVC 中,您可以通过在以下代码中添加 1 行来轻松打开匿名身份验证web.config:

<anonymousIdentification enabled="true" />
Run Code Online (Sandbox Code Playgroud)

我们可以使用匿名身份识别,即Request.AnonymousID识别您网站上未经身份验证的用户。当您需要针对访客保存购物车中的商品时,这对于电子商务体验非常有用。

更多信息:http://www.toplinestrategies.com/blogs/net/anonymous-identification-mvc

问题:

Request.AnonymousID来自System.Web,随着 ASP.NET Core 的出现而消失。

问题:

  1. 如何在 ASP.NET Core MVC 中启用匿名身份识别?
  2. 如果 1 不可能,您将如何“识别”您网站上的访问者?

注意:我不想使用会话来存储对象。

c# anonymousidentification asp.net-core-mvc

5
推荐指数
1
解决办法
2052
查看次数