一、应用身份验证、但个别目录或文件不需要身份验证
 最常见的是一个网站的后台需要验证,而前台是不需要的;一般登录页面会有验证码、而生成验证码那个页面是不需要验证的、否则验证图片是显示不出来的。
解决方法:
web.config小技巧<system.web>
web.config小技巧      
<!-- 身份验证 -->
web.config小技巧      
<authentication mode="Forms">
web.config小技巧        
<forms name=".myForm" loginUrl="login.aspx" timeout="20" protection ="All"/>
web.config小技巧      
</authentication>
web.config小技巧      
<authorization >
web.config小技巧        
<deny users ="?"/>
web.config小技巧      
</authorization>
web.config小技巧    
</system.web>
web.config小技巧  
<!-- 验证码 -->
web.config小技巧  
<location path ="CheckCode.aspx">
web.config小技巧    
<system.web >
web.config小技巧      
<authorization >
web.config小技巧        
<allow users ="*"/>
web.config小技巧      
</authorization>
web.config小技巧    
</system.web>
web.config小技巧  
</location>
使用身份验证、禁止匿名用户访问,同时对页面checkcode.aspx允许所有用户访问、即不用验证。

二、改写(不需求)web.config继承
假设IIS中有个站点A、而A站点下面有个虚拟目录B、此时可以输入:"ttp://ip址/"  访问到A站点,输入http://ip地址/B 访问到B网站;而B项目中的web.config首先会继承A站点的web.config,如果A的config有很多设置如<httpModules>,<page>等,而B项目的config没有这些设置,项目也没用到这些设置,但B的程序在运行时确会出错、原因就是它继承A的config;这个让人有点讨厌“我压根没用它、怎么会有错?且提示出错的那个文件是A的config”,可以这样解决:
A项目用到了主题
web.config小技巧<pages enableEventValidation="false" validateRequest="false" theme="default">
B项目不用
web.config小技巧<pages enableEventValidation="false" validateRequest="false" theme="">
让B的主题为空、否则B运行时提示找不到default主题目;

A的设置
web.config小技巧 <httpModules>
web.config小技巧          
<add name="SiteCache" type="SiteCache"/>
web.config小技巧        
</httpModules>
B的设置(不用的项,清除)
web.config小技巧 <httpModules>
web.config小技巧     
<clear/>
web.config小技巧 
</httpModules>
如果A.B都用到
web.config小技巧<appSettings>
web.config小技巧  
<add key="app" value="web.config小技巧" />
web.config小技巧
</appSettings>
B运行时会提示app已经加载,此时可以
web.config小技巧<appSettings>
web.config小技巧  
<remove name="app" />
web.config小技巧  
<add key="app" value="" />
web.config小技巧
</appSettings>
或者:
web.config小技巧<appSettings>
web.config小技巧  
<clear />
web.config小技巧  
<add key="app" value="" />
web.config小技巧
</appSettings>

三、禁止web.config重写
同上面的例子、如果B中的config设置必须与A中的相同,不能重写,则A的config设置
web.config小技巧    <location path="B" allowOverride="false">
web.config小技巧      
<system.web>
web.config小技巧        
<httpModules>
web.config小技巧          
<add name="SiteCache" type="SiteCache"/>
web.config小技巧        
</httpModules>
web.config小技巧      
</system.web>
web.config小技巧  
</location>
此时B的config中<httpModules>设置不能改写,须和A的设置相同。

相关文章:

  • 2022-12-23
  • 2021-09-06
  • 2021-05-20
猜你喜欢
  • 2021-12-29
  • 2021-07-29
  • 2021-09-02
  • 2021-08-27
相关资源
相似解决方案