标签: forms-authentication

双重登录ASP.Net WebForms应用程序的一些用户

我有一个使用表单身份验证的asp .net webforms应用程序.对于少数用户,我们在登录时遇到问题,他们导航到几页,然后要求他们再次登录.一旦登录第二次,他们似乎能够按预期保持登录状态.不应该要求他们第二次登录.

这是一个单一的服务器,没有网络农场,没有什么棘手的.

这只发生在少数用户身上,但似乎确实是来自同一建筑物的所有用户.我无法复制这一点,如果我们的一位培训师没有看到它发生在几个客户身上,我们甚至可能会开始否认这种情况正在发生.

有没有人见过这样的东西?

我也看到很多"会员资格证书验证失败".事件日志中的错误.这可能是相关的,但我所做的所有谷歌搜索似乎都指向网络农场等,而不是单个服务器.

UPDATE

  1. 没有代理服务器,IIS服务器和浏览器(IE8)都在同一台机器上.
  2. 安装的AV软件是Symantec Endpoint,在一台机器上,另一台用户根本没有任何AV(AV Fail!).
  3. 浏览器是IE 8,没有多余的装饰,没有一个没有默认安装的插件.
  4. 会话和用户登录超时都设置为30分钟,问题发生在用户登录的1分钟内.
  5. 日志记录显示用户只有一个IP地址.
  6. 我已经在其所有变体中尝试了sessionMode,这似乎没有任何区别.

asp.net forms-authentication

4
推荐指数
1
解决办法
1506
查看次数

如果User.IsInRole有字符串数组?

我试图建立一个自定义验证,我检查角色是否包含用户.我遇到字符串数组的问题,检查它是否包含特定值的最佳方法是什么?

    public string[] AuthRoles { get; set; }


    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {

        if (AuthRoles.Length > 0)
        {

            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {

               RedirectToRoute(filterContext,
               new
               {
                   controller = "AdminLogin",
                   action = "AdminLogin"
               });

            }
            else
            {
                bool isAuthorized = filterContext.HttpContext.User.IsInRole(this.AuthRoles.??);

                if (!isAuthorized)
                    throw new UnauthorizedAccessException("You are not authorized to view this page");
            }
        }
        else
        {
            throw new InvalidOperationException("No Role Specified");
        }
Run Code Online (Sandbox Code Playgroud)

我应该如何修改User.IsInRole的检查以便它处理数组?

c# asp.net-mvc forms-authentication

4
推荐指数
2
解决办法
2759
查看次数

ASP.NET - Web.config登录错误找不到存储过程'dbo.aspnet_CheckSchemaVersion'

我正在使用表单身份验证和gettnig以下错误:

'/'应用程序中的服务器错误.

找不到存储过程'dbo.aspnet_CheckSchemaVersion'.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

异常详细信息:System.Data.SqlClient.SqlException:找不到存储过程'dbo.aspnet_CheckSchemaVersion'.

来源错误:

在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.

堆栈跟踪:

[SqlException(0x80131904):找不到存储过程'dbo.aspnet_CheckSchemaVersion'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,Boolean breakConnection)+2030802
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection)+5009584
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()+234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+2275
System.Data.SqlClient. SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)+215
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)+987
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior) cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method,DbAsyncResult result)+1 62
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result,String methodName,Boolean sendToPipe)+178
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()+137
System.Web.Util.SecUtility.CheckSchemaVersion(ProviderBase provider,SqlConnection连接) ,String [] features,String version,Int32&schemaVersionCheck)+392
System.Web.Security.SqlMembershipProvider.CheckSchemaVersion(SqlConnection connection)+84
System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username,Boolean updateLastLoginActivityDate,Int32&status,String&password ,Int32&passwordFormat,String&passwordSalt,Int32&failedPasswordAttemptCount,Int32&failedPasswordAnswerAttemptCount,Boolean&isApproved,DateTime&lastLoginDate,DateTime&lastActivityDate)+827
System.Web.Security.SqlMembershipProvider.CheckPassword(String username,String password,Boolean updateLastLoginActivityDate,Boolean failIfNotApproved,String&salt,Int32& passwordFormat)+105
System.Web.Securit y.SqlMembershipProvider.ValidateUser(String username,String password)+106
System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e)+60
System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e)+129 System. Web.UI.WebControls.Login.AttemptLogin()127
System.Web.UI.WebControls.Login.OnBubbleEvent(对象源,EventArgs的)101 System.Web.UI.Control.RaiseBubbleEvent(对象源,EventArgs的参数)+ 37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)+125
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+167
System.Web.UI.WebControls.Button.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String …

asp.net forms-authentication login web-config

4
推荐指数
1
解决办法
2万
查看次数

允许匿名访问"内容和脚本"文件夹

我正在构建一个使用Forms身份验证的ASP.NET MVC 2网站.现在我想允许未经身份验证的用户访问"脚本和内容"文件夹,因此将加载样式表和图像.但是,它不起作用.从我在谷歌上发现的,这应该工作:

<location allowOverride="false" path="Content">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>
  <location allowOverride="false" path="Scripts">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>
Run Code Online (Sandbox Code Playgroud)

它在IIS(win7)上的ASP.NET MVC 2中不起作用.样式表和javascript请求被重定向到Account/LogOn.我该如何解决?

更新:IIS中启用了匿名身份验证.表格认证也是如此.

forms-authentication asp.net-mvc-2

4
推荐指数
1
解决办法
4848
查看次数

以编程方式检查页面是否需要基于web.config设置进行身份验证

我想知道是否有办法检查页面是否需要基于web.config设置进行身份验证.基本上如果有这样的节点

  <location path="account">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
Run Code Online (Sandbox Code Playgroud)

然后我想检查任何页面是否需要身份验证,如果它在帐户目录下,则返回true.这可能吗?

c# asp.net forms-authentication web-config

4
推荐指数
1
解决办法
2717
查看次数

注销后表单身份验证会话有效

是否有一种使来自服务器的表单身份验证会话无效的好方法?

我知道 cookie 具有嵌入式过期时间,但我想对服务器进行额外检查以验证用户是否没有手动注销。当用户手动退出时,我调用FormsAuthentication.SignOut()使 cookie 过期的方法。但是,如果我使用开发人员工具将 cookie 设置回其原始值,我仍然处于登录状态。

我能想到的一种选择是将“登录 ID”嵌入到UserData票证部分中。我的意思是每次登录都记录在数据库中,并且有一个与之关联的 ID。当用户手动注销时,我可以更新数据库记录以显示他们已经这样做了。但是,这需要我在每次对用户进行身份验证时查询数据库(不理想)。我可以维护一个缓存,但这似乎需要做很多工作,我希望有一种更简单的方法:)

谢谢!

asp.net authentication forms-authentication

4
推荐指数
1
解决办法
2440
查看次数

表单跨虚拟目录的身份验证

我正在尝试将表单auth从根应用程序共享到在虚拟目录中运行的子应用程序.我在子网站中进行身份验证时遇到问题.

在父应用程序中,一切都按预期工作.

我有以下设置:

家长申请:

  • 网址:http://localhost:1336/
  • <forms loginUrl="~/account/sign-in" protection="All" timeout="30" name=".MYAPPLICATION" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" defaultUrl="/" />

虚拟目录:

  • 网址:http://localhost:1336/subsite
  • <forms loginUrl="/account/sign-in" protection="All" timeout="30" name=".MYAPPLICATION" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="true" defaultUrl="/" />

当我尝试一个时,http://localhost:1336/subsite我得到以下流程:

  • GET for http://localhost:1336/subsite- > 302 to/account/sign-in?ReturnUrl =%2fsubsite (看起来不错)
  • 输入用户/密码
  • POSThttp://localhost:1336/account/sign-in?ReturnUrl=%2fsubsite- > 302/subsite (很棒的auth看起来很成功)
  • GET for http://localhost:1336/subsite- > 302 to/account/sign-in?ReturnUrl =%2fsubsite (IE子网站不认为其经过身份验证)

此外,我可以在浏览器的列表中看到cookie(所以它实际上在那里)

我的配置中有什么错误阻止我的子网站共享父cookie?

我在IISExpress上运行它

asp.net asp.net-mvc forms-authentication

4
推荐指数
1
解决办法
2692
查看次数

ASP网站似乎没有在Forms.Config中使用machineKey进行FormsAuthentication.Decrypt

我想从我的ASP.Net MVC 5(.Net 4.5.1,本地托管在iisexpress上,从Visual Studio运行)传递身份验证cookie到我的WCF服务(.Net 4.5.1,在本地托管在WcfSvcHost上,从中运行) Visual Studio解决方案)并在那里解密.我已将两者配置为使用相同的机器密钥(ASP的Web.config,WCF的App.config):

<machineKey validationKey="930681CA8CDC1BC09118D6B37E4A1B7712CEDBBD9FA1E35407EA1CD440C7E6F2DB9E93DADAC4098F90ACC7417DBE57C196722FC67F313A6AAE0F946E2FF731B6" decryptionKey="714C9581DA522C636B2D97D80276D5ACC02C274A11ABF117C76181B0480D4AEA" validation="SHA1" decryption="AES" />
Run Code Online (Sandbox Code Playgroud)

两者都引用相同的System.Web.dll:

C:\ Program Files(x86)\ Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\System.Web.dll(v4.0.30319)

但是当我尝试将cookieString传递给我的服务并调用时

FormsAuthenticationTicket tick = FormsAuthentication.Decrypt(cookieString);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

无法验证数据

我反过来尝试了(在WCF服务上生成假票并在ASP网站上解密),这也没有用.我可以在ASP网站上生成一张票并在那里解密就好了.我也可以在服务上生成一张票,并在那里解密它没有任何问题.

var t1 = new FormsAuthenticationTicket("foo", false, 1337);
var cookie = FormsAuthentication.Encrypt(t1);
var t2 = FormsAuthentication.Decrypt(cookie);
Run Code Online (Sandbox Code Playgroud)

我还制作了一个小型控制台应用程序,在那里创建了一个票证,并在WCF服务上解密,没有任何问题.

因此,似乎ASP网站不使用指定的密钥来加密或解密数据.

有谁知道我能做些什么来解决这个问题?

编辑:我按照本指南获取cookie并将其传递给我的服务. http://thoughtorientedarchitecture.blogspot.de/2009/10/flowing-aspnet-forms-authentication.html

然而,正如我所说,我试图复制加密cookie的价值并在一个简单的控制台应用程序中使用相同的机器密码解密它,它不起作用.

c# asp.net wcf forms-authentication machinekey

4
推荐指数
1
解决办法
8113
查看次数

MVC 5 Forms身份验证为User.Identity.Name返回null

身份验证无法在我的MVC 5应用程序中进行表单身份验证身份验证.页面被正确重定向,但User.Identity.IsAuthenticated和User.Identity.Name值为空.

我的webconfig,

  <system.web>        
    <authentication mode="Forms">
          <forms cookieless="UseCookies" defaultUrl="~/" loginUrl="~/user/signin"  name="MYAPPWeb" timeout="21600" slidingExpiration="true"/>
        </authentication>
Run Code Online (Sandbox Code Playgroud)

UserController的,

 [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SignIn(SignInViewModel user)
        {

                        UserDTO userObj;
                        using (var services = new ServiceFactory())
                        {                            
                            userObj = services.UserManagement.ValidateLoginDetails(ConfigHelper.EnvironmentString, user.TenantName, user.Username, user.Password);
                        }
                                string userID = userObj.UserID.ToString();
                                //FormsAuthentication.RedirectFromLoginPage(userID, user.RememberMe);
                                FormsAuthentication.SetAuthCookie(userID.ToString(),true);

                                FormsAuthentication.RedirectFromLoginPage(userID, false); //DO NOT REMEMBER ME

}
Run Code Online (Sandbox Code Playgroud)

HomeController(默认页面)

 public ActionResult Index()
        {

            bool x = User.Identity.IsAuthenticated; //false?
            string y = User.Identity.Name; //null?

return View();
}
Run Code Online (Sandbox Code Playgroud)

它看起来很直接,我错过了什么?请帮忙!

注意:
当我创建项目时,我选择了Windows身份验证.它创建了一些与Owin authenticnticaiton相关的配置文件(startup.auth.cs).我删除了它们并添加了上面的appsetting条目,因为它需要停止加载Owin程序集.

<add key="owin:AutomaticAppStartup" value="false"/>
Run Code Online (Sandbox Code Playgroud)

forms-authentication asp.net-mvc-5

4
推荐指数
1
解决办法
1260
查看次数

在单元测试 FormsAuthentication.SignOut() 中抛出错误

在运行我的单元测试方法时,我收到错误 FormsAuthentication.SignOut()。我已经像这样嘲笑了 httpcontext

var httpRequest = new HttpRequest("", "http://localhost/", "");
var stringWriter = new StringWriter();
var httpResponse = new HttpResponse(stringWriter);
var httpContext = new HttpContext(httpRequest, httpResponse);
var sessionContainer = new HttpSessionStateContainer(
    "id",
    new SessionStateItemCollection(),
    new HttpStaticObjectsCollection(),
    10,
    true,
    HttpCookieMode.AutoDetect,
    SessionStateMode.InProc,
    false);
SessionStateUtility.AddHttpSessionStateToContext(httpContext, sessionContainer);
var controller = new AccountController();
var requestContext = new RequestContext(new HttpContextWrapper(httpContext), new RouteData());
controller.ControllerContext = new ControllerContext(requestContext, controller);
var actual = controller.Login(new CutomerModel() { Login = "admin", Password = "Password1" });
return httpContext;
Run Code Online (Sandbox Code Playgroud)

在登录方法中

public ActionResult Login(CutomerModel …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing forms-authentication mocking httprequest

4
推荐指数
1
解决办法
956
查看次数