Several embedded resource solutions related to Asp.net custom control development, asp.net Control

Source: Internet
Author: User
Tags server hosting

Several embedded resource solutions related to Asp.net custom control development, asp.net Control
Prerequisites:The following types of resources must be displayed in the properties page.,Set<Generation operation>Attribute,Set[Embedded Resources],:

  Solutions for adding custom icons to custom controls  Method 1 : Add an icon file in *. bmp format in the custom control project and name it Same as the main control file, the extension is. bmp. For example, the main control file name is: CustomButton. cs, the icon file is named CustomButton.bmp. compile the project. Then add this control in the toolbox to see the icon effect you just set. .  Method 2 : The icon file name is different from the Master Control name , Set the following before the class: .  [ToolboxBitmap (typeof (CustomButton), @ "CustomButton1.bmp")] Public class CustomButton: CompositeControl, INamingContainer { // ... .; }  Compile a project , Then add this control in the toolbox to see the icon effect you just set. . Method 3: The icon file name is different from the Master Control name , Use the absolute path of the local machine as follows:  [ToolboxBitmap (@ "E: \ net \ CustomButton ( Test Resources File) \ CustomButton \ CustomButton1.bmp ")]  Compile a project , Then add this control in the toolbox to see the icon effect you just set. . Custom Control embedding JavaScript File Resources  1. Define metadata attributes [Assembly: WebResource ("CustomButton. CustomButton_JScript.js ", "Application/javascript")] Namespace CustomButton { // ... .; }  Where WebResource Parameter 1 is: Control namespace +. + JS script file name  2. Use  If (! Page. ClientScript. IsClientScriptIncludeRegistered ("MyJavaScript ")) { Page. ClientScript. RegisterClientScriptInclude ("MyJavaScript", Page. ClientScript. GetWebResourceUrl (This. GetType (), "CustomButton. CustomButton _ JScript. js ")); } Custom Control embedding Image (Gif/jpg And so on ) File Resources  1. Define metadata attributes  [Assembly: WebResource ("CustomButton.NoPic.gif", "image/gif")] Namespace CustomButton { // ... .; }  2. Use  String strImageSrc = Page. ClientScript. GetWebResourceUrl (This. GetType (), "CustomButton.NoPic.gif "); System. Web. UI. WebControls. Image img = new System. Web. UI. WebControls. Image (); Img. ImageUrl = strImageSrc; Other related Custom Controls :  Http://blog.csdn.net/ChengKing/category/288694.aspx
How does aspnet develop custom controls?

The following provides basic security guidelines for users and developers of custom server controls. For more information about creating custom server controls, see develop custom ASP. NET Server controls. IDE (such as Microsoft Visual Studio 2005) Simplifies the use and development of custom controls. However, no matter which IDE is used, the security rules listed below apply. For general information about ASP. NET Web Application Security, see ASP. NET Web Application Security. You can use custom server controls in Web applications in multiple ways. For example, you can directly store source code files in the App_Code folder of Web applications, use controls from Global Assembly Cache, or use community components installed through automatic installation programs (such as Visual Studio content installer. In all circumstances, preventive measures should be taken to prevent malicious code imports or code that has an unexpected but negative impact on the IDE and the server hosting components. The following provides some security rules that users of custom server controls should consider. This list may not be comprehensive enough, but you can proceed with the investigation: Do not just consider the runtime security of the control, but also consider its design-time security. For more information, see ensure the security of custom control designer components. Use the least privileged account to run ASP. NET Web applications that include imported controls. For more information about running ASP. NET processes with the lowest privilege, see configure ASP. NET process identifiers. In an IDE such as Visual Studio 2005 or quick release of Visual Web Developer, unless you need to execute management tasks, do not run applications as administrators as normal users. For more information, see User Rights and Visual Studio and User permissions and Visual Studio. view the operating system security and Windows Access Control List (ACL) of the server hosting the custom Server Control ). For example, make sure that you run ASP with only the minimum permissions required to run the application. to minimize the impact of security vulnerabilities caused by custom server controls on other hosted applications. For more information, see configure ASP. NET Process Identity. In addition, view the permissions of custom server controls and ensure that they comply with the file and folder permissions. The ASP. NET Web application identity must have this permission to work properly. For more information, see the required access control list (ACL) in ASP. NET ). Use code access security to restrict resources that can be accessed by Web applications (with custom server controls) and privileged operations that can be performed. For more information, see ASP. NET code access security. Use the. NET Framework Configuration tool (Mscorcfg. msc) to manage and configure the assembly in the Global Assembly Cache and adjust the code access security policy. Because Mscorcfg. msc is used to help senior administrators perform tasks related to application configuration, work with your system administrator to determine whether the tool meets your needs. For more information, see. NET Framework Configuration tool (Mscorcfg. msc ). For custom Server Control developers, you should follow the general best practices for security in ASP. NET application pages and controls and. NET Framework. In many cases, users of custom server controls may not understand the details or security risks of All implementations. However, you should plan this by following the established security conventions and clearly specifying all permissions required for the component to work normally. You can refer to ASP. NET Website Security,. NET Framework developer guide, basic concepts of security, and other full texts>

Development and use of aspnet Custom Controls

Protected override void AddAttributesToRender (HtmlTextWriter writer)
{
Writer. AddAttribute ("Custom", this. Custom );

Base. AddAttributesToRender (writer );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.