| A Beginner's view : Web.config
|
| |
|
In this artcle , I will be explaining the common and mostly used web.config tags, their different sections and also dicuss about securing the the config file.
Here in this article, I will be exploring the configuration files of a website. ASP.NET website configuration is normally a combination of two files:
Here, I'll concentrate on web.config and give an overview of machine.config. Every time we install the .NET framework, there is a machine.config file that is created in "C:/WINDOWS/Microsoft.NET/Framework/[Version]/CONFIG", which mainly defines:
To explore the web.config might take a book, but here, I'll try to explore all the important sections that play a pivotal role for an ASP.NET website and its deployment. Every web application inherits settings from the machine.config file, and application level setting is done in the web.config file. We can also override configurations in the machine.config file in the web.config file. But, a few settings can not be overridden because certain settings are process model settings and can't be changed on a per application basis. The entire contents of a configuration file, whether it is machine.config or web.config, is nested in a element. ASP.NET uses a multilayered configuration system that allows for using different settings for different parts of an application. For this, we must have an additional subdirectory inside the virtual directory, and these subdirectories will contain their own config files with additional settings. ASP.NET uses configuration inheritance so that each subdirectory acquires the settings from the parent directory.
Let's take an example. We have a web request http://localhost/X/Y/Z/page.aspx, where X is the root directory of the application. In this case, multiple levels of settings come into the picture.
But here, there is a limitation: we can have unlimited number of subdirectories having different settings, but the configuration at step 1 and 2 are more significant because some of the settings can not be overridden, like the Windows account that is to be used to execute the code, and other settings can be only overridden at the application root level, like the type of authentication to be used etc. Different config files are useful when we apply different security settings to different folders. The files that need to be secured would then be placed in a separate folder with a separate web.config file that defines the more stringent security settings to these files and vice versa. In the web.config, under the element, there is another element , which is used for ASP.NET settings and contains separate elements for each aspect of the configuration. There are a lot of configuration tags that are provided by the web.config file, like authentication, authorization, browserCaps, clientTargetetc., but all of these don't have that much importance (and also can't be covered in a single article ), so here, I have only concentrated on the main tags of the config file. This element is used to verify the client's identity when the client requests a page from the server. This is set at the application level. We have four types of authentication modes: "None", "Windows", "Forms", and "Passport". If we don't need any authentication, this is the setting we use:
Normally, Windows authentication is used, for which, we need to check the checkbox: Integrated Windows Authentication.
This authentication is handled by IIS. When the user sends a request to the server, IIS authenticates it and sends the authentication identity to the code.
IIS gives us four choices for the authentication modes: Anonymous, Basic, Digest, and Windows Integrated. If the user selects Anonymous, then IIS doesn't perform any authentication. For Basic authentication, the user has to provide a username and password. This authentication is very unsecure, because the user credentials are sent in clear text format over the network. Digest authentication is same as Basic, except it hashes the user's password and transmits the hashed version over the wire. So, it is more secure than Basic. For Windows Integrated authentication, passwords never cross the network. The user must still have a username and password, but the application uses either the Kerberos or a challenge/response protocol to authenticate the user. Forms authentication uses web application forms to collect user credentials, and on the basis of the credential, it takes action on a web application.
Passport authentication is provided by Microsoft. A redirect URL should be specified, and is used when the requested page is not authenticated, and then it redirects to this URL.
Here, users are authenticated using the information in Microsoft's Passport database. The advantage is, we can use existing user credentials (such as an email address and password) without forcing users to go through a separate registration process. The disadvantage is we need to go through the licensing agreement with Microsoft and pay a yearly fee based on the use. For using Passport authentication, you first install the Passport Software Development Kit (SDK) on your server. The SDK can be downloaded from here. It includes full details of implementing passport authentication in your own applications. The tag controls client access to web page resources. This element can be declared at any level (machine, site, application, subdirectory, or page).
: Using this tag, we can control access to resources on the basis of the following verbs. In these attributes, we use symbols: ? and *.? means for anonymous users/resources, and * means for all users.
: Using this tag, we can control access to resources on the basis of the following verbs:
In this section, we can configure the settings of the compiler. Here, we can have lots of attributes, but the most common ones are debug anddefaultLanguage. Setting debug to true means we want the debugging information in the browser, but it has a performance tradeoff, so normally, it is set as false. And, defaultLanguage tells ASP.NET which language compiler to use: VB or C#. This tags includes the error settings for the application, and is used to give custom error pages (user-friendly error pages) to end users. In the case that an error occurs, the website is redirected to the default URL. For enabling and disabling custom errors, we need to specify the modeattribute.
This means if there is an error of 403, then the website will redirected to the custom page accessdenied.html. Similarly for 404 as defined above. Note: If an error occurs in the custom error page itself, ASP.NET won't able to handle it. It won't try to reforward the user to the same page. Instead, it'll show the normal default client error page with a generic message. This section is used when we want to use encoding or specify a culture for the application. This is a very vast topic, and can take an article itself for explaining it. Here, we define the character set for the server to send the response to the client, which is by default is UTF-8, and the settings of which the server should use to interpret and display culturally specific strings, such as numbers and dates.
This section can be used to configure the general runtime settings of the application. The main two are:
As the name suggests, the attribute appRequestQueueLimit defines the number of requests that can be queued up on the server for processing. If there are 51 or more requests, then server would return the 503 error ("Server too busy"). The attribute executionTimeout defines the number of minutes ASP.NET will process a request before it gets timeout. As the name suggestz, it is used for tracing the execution of an application. We have here two levels of tracing: page level and application level. Application level enables the trace log of the execution of every page available in the application. If pageOutput="true", trace information will be displayed at the bottom of each page. Else, we can view the trace log in the application root folder, under the name trace.axd. traceMode="SortByTime" locaOnly="true" /> Set the attribute localOnly to false for not viewing the trace information from the client. For enabling trace at page level, set Trace="True" in the Page tag (on the top of the page). Using this tag, we can control the identity of the application. By default, Impersonation is disabled. Using Impersonation, an ASP.NET application can execute optionally with the identity of a client on whose behalf they are operating.
In this section, we tell ASP.NET where to store the session. By default, it's inproc which means storing the session values on the server. But we have four options:
Here are the other settings:
cookieless="true" This section is used to store custom application configuration like database connection strings, file paths etc. This also can be used for custom application-wide constants to store information over multiple pages. It is based on the requirements of the application.
It can be accessed from code like: ConfigurationSettings.AppSettings("Emailto"); All the values returned from it are strings. We might need some custom configuration sections based on the requirements. One of the simplest ways we can do this is to create our own named sections, and we can use existing NameValueSectionHandler components to parse them, and they can be used as key/value pairs to be accessed at run-time.
This can be read very easily accessed from the code-behind as: private string ReadCustomSection() There are more ways for using custom configuration sections. Check this article: CustomConfigurationSection. Encrypting Configuration Sections Some times, we put some sensitive data in the web.config file like connection strings, user specific details etc. It is recommended to encrypt these sections. ASP.NET supports two encryption techniques.
The way the operations perform is very simple. When retrieving information from a config file, ASP.NET automatically decrypts it and gives the plain text to the code. Similarly, if we do any updates on the config file from code, it is done the same way. We cannot update a config file directly. But, we can use WAT for updating it. Programmatic encryption techniques: If we want to do encryption programmatically, then we need to retrieve the correspondingConfigurationSection.SectionInformation object and call the ProtectSection() method. If we want to decrypt a section, then we can call the method UnprotectSetion(). Sample code is shown here: Configuration myConfig = Command line utilities: We can also use a command line utility like aspnet_regiis.exe for encryption of a config file, which is a CAB file found in C:/[WinDir]/Microsoft.NET/Framework/[Version]. For using this tool, we must create a virtual directory for the application. You can refer my article, Deploying Website at IIS, for more information. When using aspnet_regiis to protect some sections of a config file, we need to specify some command line arguments such as:
Here is the command line for an application located at http://localhost/MyApp:
如何在单元测试中使用Web.config-------单元测试第一个方法就遇到了问题,有个方法需要读取web.config中数据库连接字符串,可是测试用例里根本就不去读,百思不得其解。google了一堆网页。发现鸟食轩也遇到过同样问题,看了他的文章,恍然大悟为什么不去读了。不过鸟兄结果还是很郁闷的推荐用const替代,多少有点失望。不过在鸟兄博客的回复中有人提到复制config文件到测试项目目录中。我试了一下,果然灵验。不过要注意的是,要将web.config复制到test项目的bin目录下,然后将名字改为和程序集同名,如:TestAMR2007.dll.config,否则依然不理你哦,呵呵。----from(http://xiekeli.blogbus.com/logs/4967700.html) | ||
相关推荐
手把手教你用Multisim搭建FM直接调频电路(附完整波形分析)
本文通过Multisim仿真软件,手把手教你搭建FM直接调频电路。详细介绍了从核心概念理解、压控振荡器(VCO)参数设置、电路搭建与波形观测,到带通滤波器设计与信号优化的完整流程。通过对比滤波前后的时域波形与频谱分析,帮助读者直观理解频率调制原理,并提供了常见问题的排查思路与参数调试方法,将抽象的通信理论转化为可操作的实践技能。
maxkb添加火山引擎报错AccountOverdueError
验证失败,请检查参数是否正确: Error code: 403 - {‘error’: {‘code’: ‘AccountOverdueError’, ‘message’: ‘The request failed because your account has an overdue balance. Request id: 0217413935119540053fb2ecdd89046499c14b320664e6e3acc07’, ‘param’: ‘’, ‘type’: ‘Forbidden’}}
深度学习模型设计的方法和技巧
设计神经网络模型是一个迭代的过程,需要不断试验和调整各个组成部分,以达到最佳性能。同时,遵循良好的工程实践,如模块化设计、版本控制、文档记录等,也是成功的关键。
豆包大语言模型API调用错误码一览表
本文介绍了您可能从 API 和官方 SDK 中看到的错误代码。400原因:错误的请求,例如缺少必要参数,或者参数不符合规范等解决方法:检查请求后重试401原因:认证错误,代表服务无法对请求进行认证。签名缺失/API key解析失败/ak找不到等错误为认证错误解决方法:检查相关认证信息后重试402原因:表示客户端必须付费才能访问所请求的资源解决方法:开通相关服务403原因:权限错误,ak/sk、API key 没有对应 Endpoint 权限。
QuickFix Java 讲解(五)消息的收发与查看
本系列力求手把手教你怎样利用QuickFix Java 搭建自己的 FIX 协议收发平台,以及其中的注意事项。 所有源码的地址(免费): https://github.com/zongzhec/QuickFixPractise 这节我们讨论将Acceptor和Initiator启动以后,收到的消息极其查看方式。 6. 收发双方的通信 6.1. 启动后的通信和登录 为方便起见,这里我们使用统一的源码:https://github.com/zongzhec/QuickFixPractise ..
S7-1200g2运动控制实战:从轴组配置到程序调试
本文详细介绍了S7-1200g2运动控制功能的实战应用,从轴组配置到程序调试的全流程。通过TIA Portal中的工艺对象配置,实现单轴、同步轴组等运动控制模型,并分享常见问题排查与性能优化经验,帮助工程师快速掌握中小型自动化设备的运动控制技术。
web无法访问服务器_无法访问的Web服务器的操作过程
web无法访问服务器We would usually not bother until one fine day your website fails to respond. And if you have a website that helps you making an earning from it, then the frustration starts to build. A usua...
基于FFT的阵列方向图快速计算公式推导
因为自己毕设涉及到阵列方向图综合相关知识,最近阅读了关于方向图综合的相关文献,就其中关于使用FFT计算阵列方向图的方法进行了公式推导。 简介: 自从1965年Colley-Tukey发表快速傅里叶变换[1]论文以来,FFT在许多科学技术领域获得了广泛和成功的应用。在阵列信号处理与雷达信号处理领域,随着科技的发展,对于电尺寸较大的相控阵天线,使用公式按照级数求和计算天线阵列方向图的方法效率甚低,...
工具Acunetix web scanner 扫描的漏洞修复
1、HTML form without CSRF protection 解决:添加一个 <input type="hidden" name="session" autocomplete="off" class="layui-input" value="12345"/> 其中value的值是从后台传递过来的,提交表单时验证 2、User credentials are se
别再迷信Intel网卡了!用普通笔记本+TWINCAT3搭建EtherCAT主站的完整避坑实录
本文详细介绍了如何用普通笔记本和TWINCAT3搭建EtherCAT主站的完整避坑指南。通过破除必须使用Intel网卡的迷思,提供软件环境搭建、关键配置步骤、Wireshark抓包技巧及性能优化建议,帮助开发者低成本实现EtherCAT主站功能。
FPGA实战:用DDR3和乒乓操作解决视频帧撕裂问题(附Verilog代码)
本文详细介绍了如何利用DDR3内存和乒乓操作架构解决FPGA视频处理中的帧撕裂问题。通过多帧缓存原理、AXI接口配置和自适应乒乓操作设计,有效隔离读写操作,确保视频流稳定传输。文章包含Verilog代码实现和性能优化技巧,适用于工业相机、医疗影像等高速视频处理场景。
初步的对防盗连接的方法的设想
1,使用基于Forms验证的角色(用户组) 验证授权技术,为每个可下载文件设置一个对应的角色,每个角色就是要下载的文件ID。这个要修改we.config,可以参考<在asp.net中对web.config内容的添加 >, 2,为每一个登录的用户设定角色,用户可以多个角色,一个角色对应一个文件。 3,在IIS中设置应用程序映射,把防盗的文件的后缀映射到C:\WINDOWS\Micr...
【WorkBuddy专栏25】如何选择大模型——积分消耗、用途场景、选型决策全指南
【WorkBuddy专栏25】如何选择大模型——积分消耗、用途场景、选型决策全指南
描述 Machine.Config 和 Web.Config
.NET Framework 提供的配置管理包括范围广泛的设置,允许管理员管理 Web 应用程序及其环境。这些设置存储在 XML 配置文件中,其中一些控制计算机范围的设置,另一些控制应用程序特定的配置。可以使用任何文本编辑器编辑 XML 配置文件,如记事本或 XML 编辑器。XML 标记区分大小写,请确保使用正确的大小写形式。图 19.1 显示了管理员可以使用的用于配置 ASP.NET W
IDEA的使用指南
IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.
visio安装包
Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。
Web.Config/Web.Debug.Config/Web.Release.Config 根据发布环境转换Web.Config
Problem 在asp.net web form或者asp.net mvc在从开发环境发布到测试、生产环境时,其数据库环境、动态配置会有很大差别,特别是数据库链接字符串。我们需要每次发布都去修改web.config吗? 以数据库连接为例,本地开发时的连接字符串为: <connectionStrings> <add name="AvastinDP" c...
VB摄像头监控
该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制
创建 Web.config 文件详解
.config 文件的层次结构 .NET Framework 依赖于 .config 文件来定义配置选项。.config 文件是基于文本的 XML 文件。一个系统中可以存在多个 .config 文件,并且通常为这种情况。 .NET Framework 的系统范围配置设置是在 Machine.config 文件中定义的。Machine.config 文件位于 %SystemRoot%\M
jre9下载 jdk9
(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】
关于web.config的处理以及改进
一个修改web.config中appSettings配置节的函数 这个函数主要使用XmlDocument来解析web.config.并用SelectSingleNode()方法来定位要修改的配置节。要注意的是最后程序要Save(),所以,你的apsnet帐号必须对web.config拥有写权限. /// /// 修改web.config文件appSettings配置节中的Ad
如何通过代码修改web.config文件
网站中大部分配置存储在web.config的appSettings节中,可以通过System.Web.Configuration.WebConfigurationManager.AppSettings.Get读取相应的节,如何设置这些节点的值并保存呢? 修改web.config的内容可以使用 Configuration cfg = System.Web.Configur
web.config详解
web.config详解在开发中经常会遇到这样的情况,在部署程序时为了保密起见并不将源代码随项目一同发布,而我们开发时的环境与部署环境可能不一致(比如数据库不一样),如果在代码中保存这些配置这些信息部署时需要到用户那里更改代码再重新编译,这种部署方式非常麻烦。 在.net中提供了一种便捷的保存项目配置信息的办法,那就是利用配置文件,配置文件的文件后缀一般是.config,在asp.net中配置
创建 Web.config 文件
在“解决方案资源管理器”中,单击“刷新”图标以确认应用程序还没有 Web.config 文件。 如果已使用网站管理工具或某些其他方式来配置应用程序,则可能已自动创建了 Web.config 文件。单击“刷新”更新文件列表。 在“解决方案资源管理器”中,右击网站名称,然后单击“添加新项”。 在“
Web.Config文件发布时替换
有时候我们开发与发布Web应用程序时Web.Config中的配置可能不一样,比如数据库连接字符串。那在发布时想自动替换Web.config文件的内容如何办呢? 解决方法: 1、展开Web.Config文件时,可以看到Web.Debug.Config与Web.Release.Config这两个文件 Web.Debug.Config是用来在Debug状态下用来替换Web.config文件
Web.config,节点大全
web.config配置节点大全详解 web.config 文件查找规则: (1)如果在当前页面所在目录下存在web.config文件,查看是否存在所要查找的结 点名称,如果存在返回结果并停止查找。 (2)如果当前页面所在目录下不存在web.c
Web.Debug.config和Web.Release.config——学习笔记
参考文章:http://www.cnblogs.com/TomXu/archive/2011/11/25/2263089.html http://blog.csdn.net/yellowegg/article/details/8134469
Web.config总结
%windir%/Microsoft.NET/Framework/v2.0.50727/CONFIG目录下machine.config定义了针对当前机器的WinForm程序和asp.net应用程序的配置;web.config包含了asp.net网站的常用配置。1.配置文件查找优先级(1)如果在当前页面所在目录下存在web.config文件,查看是否存在所要查找的结点名称,如果存在...
C#的web.config文件详解
一、web.config查找的优先级 当我们要读取某个节点或者节点组信息时,按照如下方式搜索: (1)在当前页面所在目录下查找web.config文件,存在则返回结果并停止查找; (2)当前页面目录不存在web.config文件或者文件中不存在该节点,则查找上一级目录,只到搜索到网站的根目录; (3)知道网站根目录也不存在文件或不存在该节点,就查找本机的.NET FrameWork中的we




219




被折叠的 条评论
为什么被折叠?



