首页 \ 问答 \ Javascript事件处理历史[关闭](Javascript Event handling history [closed])

Javascript事件处理历史[关闭](Javascript Event handling history [closed])

虽然我确实理解Javascript事件的处理方式,但我想了解它背后的完整历史,比如事件处理是如何实际实现的(可能在标记中使用它,如<a onClick="callFunc()">

以及它如何更新到其他东西,比如从JS调用它(不显眼的JS)

现在如何使用jQuery实现它?

我只是想了解每个阶段的优势以及事件冒泡/捕获等事情


While I do understand Javascript event handling in bits and pieces, I wanted to understand the complete history behind it, like how event handling was actually implemented (may be using it within the markup like <a onClick="callFunc()"> )

And how it later got updated to something else like calling it from JS (unobtrusive JS)

to how it is implemented now using jQuery ?

I just wanted to understand the advantages at each stage and things like event bubbling/capturing, etc


原文:https://stackoverflow.com/questions/14931727
更新时间:2023-05-29 18:05

最满意答案

我使用过滤器属性来装饰我想要向Simple Auth公开的动作。 我不记得我从哪里得到这个代码(可能stackoverflow我只是没有链接所以我不能声称它的功劳)

public class BasicHttpAuthorizeAttribute : AuthorizeAttribute
    { 
protected override bool IsAuthorized(HttpActionContext actionContext)
        {
            if (Thread.CurrentPrincipal.Identity.Name.Length == 0)
            { 
                // Get the header value
                AuthenticationHeaderValue auth = actionContext.Request.Headers.Authorization;
                // ensure its schema is correct
                if (auth != null && string.Compare(auth.Scheme, "Basic", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // get the credientials
                    string credentials = UTF8Encoding.UTF8.GetString(Convert.FromBase64String(auth.Parameter));
                    int separatorIndex = credentials.IndexOf(':');
                    if (separatorIndex >= 0)
                    {
                        // get user and password
                        string passedUserName = credentials.Substring(0, separatorIndex);
                        string passedPassword = credentials.Substring(separatorIndex + 1);
                        SimpleAES crypto = new SimpleAES();
                        string userName = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERNAME));
                        string password = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERPASSWORD));

                        // validate
                        if (passedUserName == userName && passedPassword == password)
                        {
                            Thread.CurrentPrincipal = actionContext.ControllerContext.RequestContext.Principal = new GenericPrincipal(new GenericIdentity(userName, "Basic"), new string[] { });
                        }
                    }
                }
            }
            return base.IsAuthorized(actionContext);
        }
    }

然后我就这样使用它

[BasicHttpAuthorize]
public HttpResponseMessage MyExposedSimpleAuthAction()

I us a filter attribute to adorn the actions i wanted to expose to Simple Auth. I cant remember where i got this code from (probably stackoverflow i just don't have the link so i cant claim credit for it)

public class BasicHttpAuthorizeAttribute : AuthorizeAttribute
    { 
protected override bool IsAuthorized(HttpActionContext actionContext)
        {
            if (Thread.CurrentPrincipal.Identity.Name.Length == 0)
            { 
                // Get the header value
                AuthenticationHeaderValue auth = actionContext.Request.Headers.Authorization;
                // ensure its schema is correct
                if (auth != null && string.Compare(auth.Scheme, "Basic", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // get the credientials
                    string credentials = UTF8Encoding.UTF8.GetString(Convert.FromBase64String(auth.Parameter));
                    int separatorIndex = credentials.IndexOf(':');
                    if (separatorIndex >= 0)
                    {
                        // get user and password
                        string passedUserName = credentials.Substring(0, separatorIndex);
                        string passedPassword = credentials.Substring(separatorIndex + 1);
                        SimpleAES crypto = new SimpleAES();
                        string userName = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERNAME));
                        string password = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERPASSWORD));

                        // validate
                        if (passedUserName == userName && passedPassword == password)
                        {
                            Thread.CurrentPrincipal = actionContext.ControllerContext.RequestContext.Principal = new GenericPrincipal(new GenericIdentity(userName, "Basic"), new string[] { });
                        }
                    }
                }
            }
            return base.IsAuthorized(actionContext);
        }
    }

Then i use it as so

[BasicHttpAuthorize]
public HttpResponseMessage MyExposedSimpleAuthAction()

相关问答

更多
  • 所以我终于回过头来再次研究这个问题,事实证明解决方案几乎和我预期的一样简单。 解决方案是拥有两个WebSecurityConfigurerAdapter类。 这在这里描述: http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#multiple-httpsecurity 这样做有两点需要注意: WebSecurityConfigurerAdapter类必须具有不同的@Order值。 所以我用@Order(1)注 ...
  • 将CORS添加到服务器。 pip install django-cors-headers并添加标头也许这个帮助 Add CORS to the server. pip install django-cors-headers and add header maybe this help
  • 在我的情况下,似乎重新加载webapp是不够的。 通过FORM身份验证重新启动tomcat后正在使用。 ADD:FORM身份验证使用的是与BASIC / DIGEST不同的摘要算法。 因此,我的旧用户身份验证数据库不可重用。 但这是一个不同的主题。 :) It seems that reloading the webapp was not enough in my case. After restarting tomcat by FORM Authentication is being used. ADD: ...
  • 我使用过滤器属性来装饰我想要向Simple Auth公开的动作。 我不记得我从哪里得到这个代码(可能stackoverflow我只是没有链接所以我不能声称它的功劳) public class BasicHttpAuthorizeAttribute : AuthorizeAttribute { protected override bool IsAuthorized(HttpActionContext actionContext) { if (Thread.C ...
  • 我应该将auth密钥放入单独的文件中吗? 大概。 作为一般规则,您绝不应将身份验证凭据提交到源存储库。 因此,如果此文件是源控制的,我将提取硬编码值并将其替换为变量。 如何设置该变量取决于您的环境。 通常,从JSON,INI或YML配置文件中读取就足够了。 只需确保将.gitignore(或等效文件)设置为从存储库中排除该配置文件,并确保该文件位于 Web服务器的文档根目录之外,以便无法直接读取。 请注意,如果您已经提交了密钥,那么您将需要对其进行更改,因为其当前值将永久存储在您的存储库历史记录中。 Sho ...
  • 试试: SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1 您可以排除uris,只需使用条形分隔它们 Try : SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1 You can exclude uris, just seperate them using a bar |
  • 实现它的方法是实现JWT。 使用此插件很容易 按照教程: AngularJS和Laravel应用程序的基于令牌的身份验证 了解JWT: JSON Web令牌的剖析 您还可以使用Auth0 API轻松完成。 它对于小型系统是免费的。 The way to do it is implementing JWT. It is quite easy to make it work with this plugin Follow the tutorial : Token-Based Authentication for ...
  • 你在那里发布了很棒的资源。 我也使用过它,我已经构建了一个完整的(Xamarin)可移植类库,它可以自动提交每个请求等的令牌。 在ASP.NET MVC中,它就像添加 [Authorize] - 通过API控制器进行分配。 如果你正确地遵循指南,这将立即保护他们。 保护您的API后,您需要发送包含承载令牌的请求。 这是我在我的项目中实现它的方式: // First logging in and getting a token: public async Task OAuthLoginAsync ...
  • 好吧,我不喜欢这个解决方案,但它确实有效。 我所做的是检查location指令中的request_uri,如果它以/ api开头,那么我启用auth basic。 我想为此目的使用两个不同的位置,而不是在位置内的if。 这是location指令,默认情况下它已启用,如果请求匹配^ / api /.*$,则auth设置为off: # PROD location ~ ^/app\.php(/|$) { include /etc/nginx/php-mysite.conf; # Protect ...
  • HTTParty基本身份验证 auth = {username: 'user', password: 'pass'} result = HTTParty.get( "https://unicom24.ru/api/partners/requests/v1/locality/", basic_auth: auth ) HTTParty basic auth auth = {username: 'user', password: 'pass'} result = HTTParty.get( ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)