Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze ABP setting Management

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to analyze ABP setting management, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Setting management of ABP.

Start

First you define a FileOptions class that contains several configurations, and then you can use this information by injecting IOptions where you need it.

Of course, some configuration changes can be made when the module starts, such as:

Both the configuration file and the configuration in this form of code are program-level changes; some configurations are not suitable for this, such as AllowedMaxFileSize and AllowedUploadFormats here, which should be on the application interface and can be modified by the administrator. Next, let's modify the program.

Define settin

You need to define the setting before using it, and different modules can have different settings.

Modules\ file-management\ src\ Xhznl.FileManagement.Domain\ Settings\ FileManagementSettingDefinitionProvider.cs:

Public class FileManagementSettingDefinitionProvider: SettingDefinitionProvider

{

Public override void Define (ISettingDefinitionContext context)

{

/ * Define module settings here.

* Use names from FileManagementSettings class.

* /

Context.Add (new SettingDefinition (

FileManagementSettings.AllowedMaxFileSize

"1024"

L ("DisplayName:FileManagement.AllowedMaxFileSize")

L ("Description:FileManagement.AllowedMaxFileSize")

)

.WithProperty ("Group1", "File")

.WithProperty ("Group2", "Upload")

.WithProperty ("Type", "number")

New SettingDefinition (

FileManagementSettings.AllowedUploadFormats

".jpg, .jpeg, .png, .gif, .txt"

L ("DisplayName:FileManagement.AllowedUploadFormats")

L ("Description:FileManagement.AllowedUploadFormats")

)

.WithProperty ("Group1", "File")

.WithProperty ("Group2", "Upload")

.WithProperty ("Type", "text")

)

}

Private static LocalizableString L (string name)

{

Return LocalizableString.Create (name)

}

}

The above code defines two configurations: AllowedMaxFileSize and AllowedUploadFormats, and sets their default values, names, and detailed descriptions. Because the SettingUi module of EasyAbp is used in this project, there will be some fields such as Group1,Group2. For more information, please see Abp.SettingUi.

Use Settin

To read the setting information, simply inject ISettingProvider. Because the parent class ApplicationService has been injected, it is fine to use SettingProvider directly here. Get the configuration, and then you can do some logical processing, such as determining whether the size and format of the uploaded file is legal:

Public class FileAppService: FileManagementAppService, IFileAppService

{

.

[Authorize]

Public virtual async Task CreateAsync (FileUploadInputDto input) http://www.xasg120.net/ of Zhengzhou abortion Hospital

{

Var allowedMaxFileSize = await SettingProvider.GetAsync (FileManagementSettings.AllowedMaxFileSize); / / kb

Var allowedUploadFormats = (await SettingProvider.GetOrNullAsync (FileManagementSettings.AllowedUploadFormats))

Split (",", StringSplitOptions.RemoveEmptyEntries)

If (input.Bytes.Length > allowedMaxFileSize * 1024)

{

Throw new UserFriendlyException (L ["FileManagement.ExceedsTheMaximumSize", allowedMaxFileSize])

}

If (allowedUploadFormats = = null | |! allowedUploadFormats.Contains (Path.GetExtension (input.Name)

{

Throw new UserFriendlyException (L ["FileManagement.NotValidFormat"])

}

.

}

}

Front-end settings interface:

The following settings can be modified to test:

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report