在这篇文章中,我们将带领您了解我可以在web.config中为maxJsonLength设置无限长度吗?的全貌,同时,我们还将为您介绍有关.net–嵌套的app.config(web.config)文
在这篇文章中,我们将带领您了解我可以在 web.config 中为 maxJsonLength 设置无限长度吗?的全貌,同时,我们还将为您介绍有关.net – 嵌套的app.config(web.config)文件、.net 调用 https 协议 WebService,添加 web 引用后 web.config 的修改、0701-spring cloud config-简介、Config Server开发、Config Client开发、App.config/Web.config 中特殊字符的处理的知识,以帮助您更好地理解这个主题。
本文目录一览:- 我可以在 web.config 中为 maxJsonLength 设置无限长度吗?
- .net – 嵌套的app.config(web.config)文件
- .net 调用 https 协议 WebService,添加 web 引用后 web.config 的修改
- 0701-spring cloud config-简介、Config Server开发、Config Client开发
- App.config/Web.config 中特殊字符的处理
我可以在 web.config 中为 maxJsonLength 设置无限长度吗?
我正在使用 jQuery 的自动完成功能。当我尝试检索超过 17000 条记录的列表(每条记录的长度不超过 10 个字符)时,它超出了长度并引发错误:
异常信息:
异常类型:InvalidOperationException
异常消息:使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了 maxJsonLength
属性上设置的值。
maxJsonLength
我可以为in设置无限长度web.config
吗?如果不是,我可以设置的最大长度是多少?
答案1
小编典典MaxJsonLength属性不能无限制,是一个整数属性,默认为
102400 (100k)。
您可以MaxJsonLength
在 web.config 上设置属性:
<configuration> <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="50000000"/> </webServices> </scripting> </system.web.extensions></configuration>
.net – 嵌套的app.config(web.config)文件
为什么我需要这是因为源控制问题.有关详细说明,请参阅this
非常感谢任何其他根本问题的解决方案.
解决方法
例如,要将应用程序设置放在单独的文件中,请在名为“configuration”的子文件夹中:
<appSettings configSource="Configuration\AppSettings.config"/>
然后在AppSettings.config中,只需正常包含appSettings标记:
<appSettings> <add key="somekey" value="someValue" /> </appSettings>
.net 调用 https 协议 WebService,添加 web 引用后 web.config 的修改
可以通过以下方式添加 web 引用:
添加应用后,web.config 文件会添加以下配置:
如果引用的是 http 协议接口,此时就可以在代码中直接实例化 webservice,没有问题。但如果引用的 https 协议接口,此处就要把 webservice 地址改为 https, 不然就会报 “The request failed with an empty response” 的错误,十分坑人。
【原文出处】http://www.51aras.com/?id=45
0701-spring cloud config-简介、Config Server开发、Config Client开发
一、概述
参看地址:
https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_spring_cloud_config
https://gitee.com/itmuch/spring-cloud-book
1.1、为什么需要统一管理配置
集中管理、不同环境不同配置、运行期间动态调整配置、自动刷新
默认都是配置在配置文件中、数据库等中
1.2、简介
主要有两种分布式配置Zookeeper、Consul。
其实还有许多,如百度的disconf、阿里的diamond、携程的apollo
为分布式系统外部化配置提供了服务器端和客户端的支持。它包括Config Server和Config Client两部分。由于Config Server和Config Client都实现了对Spring Environment 和PropertySource抽象的映射,因此,Spring Cloud Config非常适合Spring应用程序,当然也可以与任何其他语言编写的应用程序配合使用。
Config Server是一个可横向扩展、集中式的配置服务器。它用于集中管理应用程序各个环境下的配置。默认使用Git存储配置内容(也可以使用Subversion,本地文件系统或Vault存储配置。)因此可以方便的实现对配置的版本控制与内容审计等
Config Client是Config Server的客户端,用于操作存储在Config Server中的配置属性。
1.3、架构图
在Config Server可以有dev、stage、prod等环境
二、Config Server开发
2.1、项目搭建
如git地址:https://github.com/bjlhx15/spring-cloud.git
增加pom
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
启动类增加注解
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
2.2、增加配置项目git
如:https://github.com/bjlhx15/spring-cloud-config-test-repo.git
2.3、在application.yml中增加
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://github.com/bjlhx15/spring-cloud-config-test-repo
启动项目测试即可.
2.4、访问地址
HTTP服务具有以下形式的资源映射规则:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
其实是按照格式随意拼接即可。如:http://localhost:8080/aa-profile.properties 或者 http://localhost:8080/aa-profile.yml
其中label是git的分支版本。
2.5、测试
增加foobar-dev.yml测试。
访问:http://localhost:8080/foobar-dev.yml,发现是配置的文件,。
即访问优先级:先找到能匹配的文件【label/具体文件名】,如果不匹配即找到application配置文件。
平时使用建议使用一个配置文件即可
三、Config Client开发
3.1、创建项目
git地址:https://github.com/bjlhx15/spring-cloud.git
增加pom【注意是spring-cloud-starter-config】
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
配置文件
新增一个bootstrap.yml
spring:
cloud:
config:
uri: http://localhost:8080
name: foobar
profile: dev
label: master # 当configserver的后端存储是Git时,默认就是master
application: #和配置文件匹配最好
name: foobar
在application.yml
server:
port: 8040
原因是:Spring云上下文
Spring Cloud应用程序通过创建“bootstrap”上下文来运行,该上下文是主应用程序的父上下文。【bootstrap.yml 优先级高于application.yml】开箱即用,它负责从外部源加载配置属性,并且还解密本地外部配置文件中的属性。这两个上下文共享一个环境,它是任何Spring应用程序的外部属性的来源。bootstrap属性以高优先级添加,因此默认情况下它们不能被本地配置覆盖。
bootstrap程序上下文默认约定:使用bootstrap.yml【bootstrap.properties】覆盖application.yml(或.properties)
但是可以使用spring.cloud.bootstrap.enabled=false禁用
bootstrap.*里面的配置→链接Config Server,加载远程配置之后→在加载application.*配置
2.2、增加启动类
@SpringBootApplication
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}
2.3、增加测试
@RestController
public class ConfigClientController {
// 传统方式需要在配置文件加上配置 ,但是优先级低于使用bootstap加载的配置
@Value("${profile}")
private String profile;
@GetMapping("/profile")
public String getProfile() {
return this.profile;
}
}
注意点:
1、pom的spring-cloud-starter-config不要引错;
2、不要不适用bootstrap.yml。否则默认是8888端口
3、如果本地属性也有远端属性,以bootstrap.yml先与本地application为主,故使用远端属性profile
4、注意git上的配置文件如果是yml类型,注意属性“:”后有空格。。
App.config/Web.config 中特殊字符的处理
我们知道在应用程序中嵌入连接字符串可能导致安全漏洞和维护问题。使用 Ildasm.exe(MSIL 反汇编程序) 工具可以查看编译到应用程序源代码中的未加密连接字符串。此外,如果连接字符串发生更改,则必须重新编译应用程序。因此,强烈建议将连接字符串存储在应用程序配置文件中。
最近在学习SQL Server时遇到连接字符串包含特殊字符出现编译错误的问题。
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="DBconnStr" connectionString="Data Source=.;Initial Catalog=MyTest;User ID=sa;PassWord=123&456"/>
</connectionStrings>
</configuration>
由于数据库连接的密码中含有特殊字符"&",编译时出现如下如下错误信息:
显然编译器不认识"&456",怎么解决呢,总不能更换密码吧?
事实上App.config是xml文件,在xml文件中特殊字符要进行HTML转义。
HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用。这些符号是不显示在我们最终看到的网页里的,那如果我们希望在网页中显示这些符号,就要用到HTML转义字符串(Escape Sequence)了
HTML特殊转义字符列表
最常用的字符实体
显示
说明
实体名称
实体编号
空格
 
<
小于
<
<
>
大于
>
>
&
&符号
&
&
"
双引号
"
"
©
版权
©
©
®
已注册商标
®
®
™
商标(美国)
™
™
×
乘号
×
×
÷
除号
÷
÷
所以只要把"&"进行转义就可以了,将PassWord改为
PassWord=123&456"
成功通过编译。
http://www.cnblogs.com/fordwayne/p/3200470.html
今天关于我可以在 web.config 中为 maxJsonLength 设置无限长度吗?的介绍到此结束,谢谢您的阅读,有关.net – 嵌套的app.config(web.config)文件、.net 调用 https 协议 WebService,添加 web 引用后 web.config 的修改、0701-spring cloud config-简介、Config Server开发、Config Client开发、App.config/Web.config 中特殊字符的处理等更多相关知识的信息可以在本站进行查询。
本文标签: