我复制了以前的项目并将其重命名.一旦我成功重命名所有名称空间并正确构建.运行应用程序时出现以下错误:
The following errors occurred while attempting to load the app.
- The OwinStartup attribute discovered in assembly 'User Manager Interface' referencing startup type 'User_Manager_Interface.Startup' conflicts with the attribute in assembly 'Service Monitor Web Interface' referencing startup type 'Service_Monitor_Web_Interface.Startup' because they have the same FriendlyName ''. Remove or rename one of the attributes, or reference the desired type directly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN …Run Code Online (Sandbox Code Playgroud) 如何实现自动注销计时器.
所以基本上如果用户在x分钟内处于非活动状态,他们的会话结束了
我试过了:
<system.web>
<sessionState timeout="1"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.
这是我的启动中的代码:
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
}
Run Code Online (Sandbox Code Playgroud)
这说我正在使用cookie身份验证.所以,如果我能做到,我不会做什么.
asp.net-mvc asp.net-authentication owin asp.net-mvc-5 asp.net-identity
我知道我可以使用声明来声明用户:
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, "Peter"));
claims.Add(new Claim(ClaimTypes.Email, "peter@domain.com"));
Run Code Online (Sandbox Code Playgroud)
但是,我应该如何存储"基于角色"的声明?例如:
用户是超级管理员.
claims.Add(new Claim("IsSuperAdmin, "true"));
Run Code Online (Sandbox Code Playgroud)
值参数"true"感觉完全冗余.如何使用索赔表达此陈述?
c# claims-based-identity asp.net-authentication asp.net-identity asp.net-web-api2
为了增加会话超时,我似乎会使用以下设置:
<system.web>
<sessionState mode="InProc" timeout="20" />
/* Etc... */
</system.web>
Run Code Online (Sandbox Code Playgroud)
此处超时设置为20分钟(默认值).而且,显然,最大值是525,600分钟,或一年.
我可以在一周后回到Facebook,我仍然登录.这就是我希望我的应用程序运行的方式.但根据这个答案,这可能会对性能产生负面影响,因为"您的非活动会话将保留在Web服务器内存中,这可能导致应用程序池回收,这将导致所有用户丢失所有会话."
有谁知道这个性能命中的细节?并且,如果它是真实的,是否有更高效的方式来保持用户登录像Facebook这样的网站?
更新:
下面是我当前web.config文件的相关部分.
<system.web>
<authentication mode="None" />
<sessionState mode="InProc" timeout="60" />
<compilation debug="true" targetFramework="4.6" />
<httpRuntime targetFramework="4.5.2" executionTimeout="240" maxRequestLength="20480" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
<customErrors mode="Off"></customErrors>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="20971520" />
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
更新2:
看起来我错误地将两个问题(身份验证和会话状态)混为一谈.我为没有正确排序我正在谷歌搜索的一些问题而道歉.我的目标只是延长用户登录的时间.
有很多关于设置asp.net成员资格,角色提供者等的问题(和信息).您是否应该使用microsoft提供的内置平台,或者角色扩展您自己的基类和角色.
我决定扩展默认提供程序并实现我自己的成员资格和角色提供程序.现在我的问题,特别是围绕角色身份验证.
传统上,您可以创建角色,例如"经理,管理员,员工,超级用户"或任何您拥有的角色.但是对于我认为是更精细控制的权限,您应该/应该做什么?让我详细说明......
在我的asp.net mvc网站中,我有不同的领域,如管理,管理,消息传递,报告等.我会为"管理员","经理","报告者"等各个角色创建角色.如果没有相应的角色,您可以无法访问该网站的该区域.所以我会在类级别锁定整个控制器.
但现在以一个地区为例; 消息,并说我想为CRUD获得更好的谷物权限; 创建消息,查看/阅读消息,编辑消息,删除消息等.
最后我的问题.如何实现这种更精细的控制?我看到的一种方法(不确定它是否是一个好方法),就是为所有东西创建asp.net成员角色.所以我可能......
Messenger(广义级角色),CreateMessage,ReadMessage,EditMessage,DeleteMessage.
一方面,我希望一些用户能够阅读/查看消息.但不一定要创建或删除它们.单个控制器操作可以应用特定角色.
你觉得这种方法有什么问题吗?你有更好的主意吗?
迄今解决方案
我决定创建自己的架构并实现自定义成员资格和角色提供程序.我的架构包括;
将在第二天或第二天离开,但是当我有机会时会更新更多信息.
asp.net-mvc asp.net-membership asp.net-authentication asp.net-roles
我正在尝试使用asp.net web api创建一个休息服务,一切正常,但我现在遇到了如何处理身份验证.
我有点困惑从哪里开始,这是我一直在想的.
我有一个休息api我正在开发包含许多资源,每个资源都需要用户注册,这样做的最佳动作是什么?我是否应该在每次调用服务时在标头中发送用户名和密码,以便我可以使用服务器进行身份验证
AuthorizationFilterAttribute
我应该至少加密它吗?我真的很想知道其他人在做什么,我知道有一个创建令牌的概念(我认为这将是短暂的)因此用户将进行身份验证,然后将收到一个令牌,然后这个令牌将被发送进一步调用该服务.我认为令牌需要短暂存在吗?那么当令牌到期时我该如何处理这个问题呢?
我还有一个用于注册新用户的资源,实际上唯一会调用它的是我的客户端(android,iphone).我应该免费使用任何身份验证方法,或者使用硬编码密码或类似的东西,以便至少没有其他人可以注册新用户?请记住,该服务将在互联网上公开.
我真的很感激任何人对此有任何反馈.
我似乎无法找到正确的方法,我当然希望第一次尝试正确,所以我不必完全重构服务.
提前致谢
asp.net rest wcf-rest asp.net-authentication asp.net-web-api
我目前正在ASP.NET中进行自定义登录.我已经修改了Login Control的代码以使用我的数据库而不是Aspnet表.这是我的代码示例;
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// Custom login control
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
try
{
string uname = Login1.UserName.Trim();
string password = Login1.Password.Trim();
bool flag = AuthenticateUser(uname, password);
if (flag == true)
{
e.Authenticated = true;
Login1.DestinationPageUrl = "Default.aspx";
}
else
e.Authenticated = false;
} …Run Code Online (Sandbox Code Playgroud) 我遇到一个问题,我似乎无法让我的身份服务器注销以首先显示确认。我从github下载了IdentityServer4的源代码,在Models文件夹中找到了参数:LogoutRequest.cs、ShowSignOutPrompt。除了在注销期间检查之外,IdentityServer 中没有对其进行任何引用。
在调试中,我发现它是错误的。我不知道应该在哪里设置,我已经检查了服务器和客户端上的客户端配置选项,以及服务器启动的选项。
我在客户端代码中找不到“ShowSignoutPrompt”的实例(我当前使用的是 IdentityServer3 Owin 混合客户端示例)。
代码流程如下:我们的默认布局中有一个按钮,可以触发客户端的 AccountController.Signout():
public void Signout()
{
Request.GetOwinContext().Authentication.SignOut();
}
Run Code Online (Sandbox Code Playgroud)
从那里开始,我不太确定如何实现,但下一个点是 IdentityServer 的 AccountController.Logout(string logoutId)。该方法构建注销提示视图(使用 AccountServices.BuildLogoutViewModelAsync 中的检查)并将其返回到用户的浏览器。不将 ShowSignoutPrompt 设置为 false 的唯一正常工作方法是将 PostLogoutRedirectUri 设置为“/signout-callback-oidc”。我不知道为什么。
当用户在上面生成的视图上单击“yes”时,它将转到 IdSrvr 的 AccountController.Logout(LogoutInputModel model)。我正在尝试更改该方法的最后一行:
return View("LoggedOut", vm);
Run Code Online (Sandbox Code Playgroud)
到:
return Redirect(vm.PostLogoutRedirectUri);
Run Code Online (Sandbox Code Playgroud)
这里还有另一个问题,即使我在客户端配置上设置了 PostRedirectUri,这里的 PostRedirectUri 也是空的(好吧,就此而言,Identity Server 的客户端配置也有它)。
我正在学习ASP.NET Core 2.0和IdentityServer4上的安全性.我使用IdentityServer,Api和ASP.NET MVC Client App设置项目.
ConfigureServiceClient App上的方法如下所示.在这里,我的困惑DefaultScheme和DefaultChallegeScheme.配置那些有什么意义?如果可能的话,关于它如何工作的详细描述将非常有用.
我已经看到了DefaultScheme,DefaultSignScheme但也有效,但它是如何工作的?这些有什么区别?
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
//options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
//options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie("Cookies")
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.SignInScheme = "Cookies";
options.RequireHttpsMetadata = false;
options.Authority = "http://localhost:5000/";
options.ClientId = "mvcclient";
options.SaveTokens = true;
});
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 .NET Core 2.1 Web 应用程序开发CookieAuthentication. 出于某种原因ExpireTimeSpan,Cookie.Expiration在CookieAuthenticationOptions对象上设置和不会对 Cookie 生存期产生影响。Chrome 始终显示相同的过期日期1969-12-31T23:59:59.000Z。所以在关闭浏览器窗口后,cookie 消失了。
启动文件
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache();
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = new PathString("/Account/Login/");
options.AccessDeniedPath = new PathString("/Account/Login/");
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.Cookie.Expiration = TimeSpan.FromDays(14);
options.ExpireTimeSpan = TimeSpan.FromDays(14);
});
services.AddMvc(options =>
{
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
services.AddAntiforgery(options => options.HeaderName = "X-CSRF-TOKEN");
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
var …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-authentication asp.net-core asp.net-core-2.0
asp.net-mvc ×5
asp.net ×4
c# ×3
asp.net-core ×2
owin ×2
.net ×1
rest ×1
wcf-rest ×1
web-config ×1