针对IISExpressweb.config设置和〇这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展0701-springcloudconfig-简介、ConfigServer开发、Conf
针对IIS Express web.config 设置和〇这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展0701-spring cloud config-简介、Config Server开发、Config Client开发、Asp.Net Core 应用程序在 IIS Express 中运行,但不在 IIS 应用程序部署中、asp.net – IIS Web.Config 301重定向查询字符串参数(?)、Config Toolkit 依赖& 分布配置工具包等相关知识,希望可以帮助到你。
本文目录一览:- IIS Express web.config 设置(〇)(iis配置web)
- 0701-spring cloud config-简介、Config Server开发、Config Client开发
- Asp.Net Core 应用程序在 IIS Express 中运行,但不在 IIS 应用程序部署中
- asp.net – IIS Web.Config 301重定向查询字符串参数(?)
- 依赖& 分布配置工具包">Config Toolkit 依赖& 分布配置工具包
IIS Express web.config 设置(〇)(iis配置web)
被 IIS Express 指向的站点目录下大多有个web.config文件用于该网站单独设置。
0.常见结构
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
</system.webServer>
</configuration>
首行是XML的标识,因为使用的XML,configuration包裹着的是设置。以下出现设置的XML时都会包括父级标签,这样便于知道这个设置要放在哪里。
1.security标签
这个标签涉及一些安全问题相关的设置。例如:
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="True"/>
</security>
</system.webServer>
在单入口的URL路由中,URL如果包含加号(+)这种符号时,默认IIS Express是不会交给站点程序处理的,这时会给出一个错误界面。但是我们往往希望给出的错误界面统一,所以修改这个设置可以让这种符号通过,再有站点程序做出处理给出页面。requestFiltering里设置allowDoubleEscaping为True就是允许这种“双转义字符”通过。
2.rewrite标签
同样在system.webServer标签下的rewrite标签可以起到重写或重定向的功能。
<system.webServer>
<rewrite>
<rules>
<rule name="Entry">
<match url=".*" />
<action type="Rewrite" url="/index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
以上是一个设置单入口的例子,rewrite标签下rules里可以放置多个rule(注意,上级是有s的)。rule有个name的属性,命名了这个rule。match标签的url是用于匹配URL的正则表达式。action标签用于真正的路由功能,type里Rewrite是重写,Redirect是重定向,url是目的URL。
3.defaultDocument标签
该标签可以设置可被IIS Express默认为首页也就是URL只有域名的默认页面文件。
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
这个例子里files标签里clear标签清除了系统默认的设置。查看IIS Express 的applicationhost.config文件是可以看到默认的。add标签就是把这种文件名加进默认列表中。
4.handlers标签
在该标签下添加子元素add来添加处理器(handler),这里以启用PHP的fastCgi为例:
</system.webServer>
<handlers accessPolicy="Read, Script">
<add name="PHP7_0_FastCGI" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="D:\PHP-7.0.4\php-cgi.exe" resourceType="Either"/>
</handlers>
</system.webServer>
在applicationhost.config的location标签下设置的话所有项目(例如其他.Net)都会打开PHPfastCgi,所以在web.config里设置会比较好。
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类型,注意属性“:”后有空格。。
Asp.Net Core 应用程序在 IIS Express 中运行,但不在 IIS 应用程序部署中
如何解决Asp.Net Core 应用程序在 IIS Express 中运行,但不在 IIS 应用程序部署中
我有一个无法解决的问题,我需要一些帮助。
我目前正在创建一个 ASP.Net Core 应用程序,我使用实体框架从数据库中获取数据。 在我的简单测试应用程序中,我只是从数据库中搭建了模型,并按照 Microsoft 文档的说明在 appsettings 和 Startup.cs 中添加了连接字符串。 在控制器中,我只是从表中获取记录并将它们显示在视图中。当我在 IIS Express 中运行它时工作正常,但是当我在 IIS 中部署应用程序并尝试调试它时,当代码尝试从表中获取数据时应用程序停止并显示此异常:
Microsoft.Data.sqlClient.sqlException: ''与网络相关的或 建立连接时发生特定于实例的错误 sql 服务器。服务器未找到或无法访问。核实 实例名称正确并且 sql Server 配置为 允许远程连接。 (提供者:SNI_PN11,错误:50 - 本地 发生数据库运行时错误。无法创建自动实例。 有关错误详细信息,请参阅 Windows 应用程序事件日志。
)''
启动:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddDbContext<PushNotificationContextContext>(options =>
options.UsesqlServer(Configuration.GetConnectionString("PushNotificationContext")));
}
控制器:
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly PushNotificationContextContext _context;
public HomeController(ILogger<HomeController> logger,PushNotificationContextContext context)
{
_logger = logger;
_context = context;
}
public IActionResult Index()
{
HomeModel model = new HomeModel();
model.AppUserList = _context.AppUsers.Take(10).ToList();
return View(model);
}
public IActionResult Privacy()
{
return View();
}
[responsecache(Duration = 0,Location = responsecacheLocation.None,NoStore = true)]
public IActionResult Error()
{
return View(new Errorviewmodel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
主要问题是一周前我制作了一个简单的应用程序,它可以在 IIS 上使用相同的连接字符串正常运行。我没有在 sql Management Studio 中更改任何内容。该应用程序也不会在其他电脑上播放。我知道有类似的问题,但没有一个能解决我的问题。
解决方法
此错误通常表示客户端找不到 SQL Server 实例。这通常发生在至少存在以下问题之一时:
- 托管 SQL Server 的计算机名称
- 实例无法解析正确的 IP
- 未正确指定 TCP 端口号
关于如何解决连接到 SQL Server 数据库引擎的问题,您可以参考此链接:Troubleshoot 。
asp.net – IIS Web.Config 301重定向查询字符串参数(?)
<rule name="blog" stopProcessing="true"> <match url="en/blog.aspx?Id=9" /> <action type="Redirect" url="http://www.mynewurl.com" redirectType="Permanent" /> </rule>
我可以重定向“en / blog.aspx”,但我无法仅重定向“en / blog.aspx?Id = 9”.
有任何想法吗?
解决方法
/en/blog.aspx?Id=9将重定向到http://www.newurl.com.
<rule name="blog" stopProcessing="true"> <match url="en/blog.aspx$" /> <conditions> <add input="{QUERY_STRING}" pattern="Id=9" /> </conditions> <action type="Redirect" url="http://www.newurl.com" redirectType="Permanent" /> </rule>
在这里找到解决方案:301 redirect not working in IIS 7
依赖& 分布配置工具包" alt="Config Toolkit 依赖& 分布配置工具包">
依赖& 分布配置工具包">Config Toolkit 依赖& 分布配置工具包
Config Toolkit <a href="https://github.com/dangdangdotcom/config-toolkit#%E4%BE%9D%E8%B5%96"></a>依赖<a href="https://github.com/dangdangdotcom/config-toolkit#%E6%A8%A1%E5%9D%97">& 介绍
Config Toolkit 是大型集群和分布式应用配置工具包。Config toolkit 用于简化从本地配置文件到
zookeeper 的迁移。
在大型集群和分布式应用中,配置不宜分散到集群结点中,应该集中管理.
依赖
-
JAVA 7+
-
TOMCAT 7+ for ConfigWeb
模块
-
Config Toolkit - 封装应用属性配置的获取及更新
-
ConfigWeb - 提供web界面维护属性配置,提供配置导入导出功能
特性
-
集中管理集群配置
-
实现配置热更新
-
多配置源支持,内置支持zookeeper、本地文件、http协议
-
Spring集成
-
本地配置覆盖
-
配置管理web界面
-
版本控制,支持灰度发布
-
支持为配置项添加注释
Quick
Start
zookeeper)load properties from zookeeper
ZookeeperConfigProfile configProfile = new ZookeeperConfigProfile("zoo.host1:8181", "/projectx/modulex", "1.0.0"); GeneralConfigGroup propertyGroup1 = new ZookeeperConfigGroup(configProfile, "property-group1");
classpath-file)load properties from classpath file
FileConfigProfile configProfile = new FileConfigProfile("UTF8", "properties"); ConfigGroup configGroup = new FileConfigGroup(configProfile, "classpath:property-group1.properties");
from-classpath-file)load xml properties from classpath file
FileConfigProfile configProfile = new FileConfigProfile("UTF8", "xml"); ConfigGroup configGroup = new FileConfigGroup(configProfile, "classpath:property-group1.xml");
file)load properties from file
FileConfigProfile configProfile = new FileConfigProfile("UTF8", "properties"); ConfigGroup configGroup = new FileConfigGroup(configProfile, "file:/Users/yuxuanwang/Work/git/config-toolkit/config-toolkit-demo/src/main/resources/property-group1.properties");
http)load properties from http
FileConfigProfile configProfile = new FileConfigProfile("UTF8", "properties"); ConfigGroup configGroup = new FileConfigGroup(configProfile, "http://crnlmchina.github.io/config-group.properties");
Config Toolkit <a href="https://github.com/dangdangdotcom/config-toolkit#%E4%BE%9D%E8%B5%96"></a>依赖<a href="https://github.com/dangdangdotcom/config-toolkit#%E6%A8%A1%E5%9D%97">& 官网
依赖&官方网站" rel="nofollow" target="_blank">https://github.com/dangdangdotcom/config-toolkit
今天的关于IIS Express web.config 设置和〇的分享已经结束,谢谢您的关注,如果想了解更多关于0701-spring cloud config-简介、Config Server开发、Config Client开发、Asp.Net Core 应用程序在 IIS Express 中运行,但不在 IIS 应用程序部署中、asp.net – IIS Web.Config 301重定向查询字符串参数(?)、Config Toolkit 依赖& 分布配置工具包的相关知识,请在本站进行查询。
本文标签: