Danh mục

Beginning Ajax with ASP.NET- P15

Số trang: 15      Loại file: pdf      Dung lượng: 361.46 KB      Lượt xem: 17      Lượt tải: 0    
10.10.2023

Phí tải xuống: 3,000 VND Tải xuống file đầy đủ (15 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Beginning Ajax with ASP.NET- P15:Thank you for purchasing Beginning Ajax with ASP.NET. We know that you have a lot of options whenselecting a programming book and are glad that you have chosen ours. We’re sure you will be pleasedwith the relevant content and high quality you have come to expect from the Wrox Press line of books.
Nội dung trích xuất từ tài liệu:
Beginning Ajax with ASP.NET- P15Chapter 8 Listing 8-3: (continued) 38. if(prototypeJs.Length > 0) 39. RegisterClientScriptBlock(page, Constant.AjaxID + “.prototype”, 40. “”); 41. 42. if(coreJs.Length > 0) 43. RegisterClientScriptBlock(page, Constant.AjaxID + “.core”, 44. “”); 45. 46. if(convertersJs.Length > 0) 47. RegisterClientScriptBlock(page, Constant.AjaxID + “.converters”, 48. “”); 49. 50. 51. if(Settings.TokenEnabled) 52. { 53. RegisterClientScriptBlock(page, Constant.AjaxID + “.token”, 54. “AjaxPro.token = \”” + CurrentAjaxToken + “\”;”); 55. } 56. } Being as flexible as possible, the library allows you to set these property values with additional Web.Config entries. The only thing you’ve done so far in the Web.Config is to wire up the Ajax Pro page handler. The library has defined a custom section that you can use in your Web.Config. This is processed by the AjaxPro.AjaxSettingsSectionHandler, found in the /Configuration/ AjaxSettingsSectionHandler.cs file.Try It Out Adding Custom Sections to Your Web.Config File Fortunately, ASP.NET has framework calls that make it really easy to add custom sections to your Web.Config file. Listing 8-4 shows a sample entry in your Web.Config to override the several default property and actions of the Ajax.NET Pro library. Listing 8-5 shows how the library reads those overridden values. Listing 8-4: Web.Config configSections Sample ... 01. 02. 03. 06. 07. 08.186 Anatomy of Ajax.NET Pro Library 09. 10. 11. 12. 13. 14. 15. 18. 19. 20. 21. 27. 28. ... How It Works ❑ The first custom setting in Listing 8-4 is the urlNameSpaceMappings on line 11. This setting allows you to mask your JavaScript calls so that you do not expose the class name and assembly names in your application. You may or may not be able to use this, depending on the version of ASP.NET and Visual Studio that you are using. If you know the name of your final assembly, then you can add this masking. If you’re using dynamic compiling, as you did in Listing 8-1, then you can’t use this mask because you don’t know the assembly name beforehand. The benefit to masking your class and assembly names is that this removes the ability of someone to discover the internal knowledge of your application. ❑ Next is jsonConverters. This is the section that enables you to instruct Ajax.NET Pro to load your JavaScript JSON converters. In the commented section, on lines 15 and 16, you can see the format of loading these converters. Converters can be removed and added with the standard and nodes. Debugging can also be turned on or off in this section. If debugging is turned on, and an excep- tion returned in the Response.Error object, then the exception will contain more information than just the exception text, such as Stack, TargetSize, and Source information. ❑ Ajax.NET Pro supports a token concept that tries to confirm that requests are coming from clients that you originally served content to. This is to help eliminate spoofing of your site. Because the calls back into the server are simple JavaScript calls, it’s possible to execute JavaScript from other pages against your site. If the token is enabled and the password is set, then a security token is placed in the head of the page that is rendered. AjaxPro.token = “f5274a7d77bc2a417b22efb3dfda9ba8”; 187Chapter 8 This token is a hash that is made up of several parameters about the user, including IP address, the site being visiting, the browser being used, and the password you supplied. This makes it much more difficult to try hacking routines from another machine against your site. The token should be enabled in all cases. It’s a very nice feature that makes hacking your site more difficult. ❑ Refresh your memory with Listing 8-1, specifically with the line number 1. Script replacements allow you to use scripts other than the default scripts that were installed with Ajax.NET Pro. Maybe you have a static file that you’ve added some debugging code to that you’d like to use while you’re debugging your application, but not once you deploy your application. Having these replacement script options in Web.Config is great because you can switch it without recompiling your application. How would you create an overridden core, prototype, or converter file? Don’t you still need all the base functionality that the original files offer? The answer is yes, you do, but that doesn’t mean that you can’t add you own debugging or other code into that script. Open your browser and point it to your web application, /AjaxPro/core.ashx. Do a view source, and you now have a copy of the core.ashx JavaScript file. Save this in your appli- cation as /scripts/debugcore.js. You might play with simply adding an alert() method in a few places, just to see it work. Now to try that debugcore.js in your application, add Listing 8-4 line 22 to your Web.Config. Set the path of the core to “~/scripts/debugcore.js”. Sa ...

Tài liệu được xem nhiều: