Web应用程序中的服务器错误 (<authentication mode="Forms">)

本文详细阐述了在将网站项目导入Visual Studio后遇到的运行错误,并提供了针对性的解决方案,包括检查WebConfig配置文件的位置、数量及内容,以及在IIS中正确配置应用程序名。同时强调了移除WebConfig文件中重复设置的节点的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    今天把做的一个网站项目导入VS后,运行出现下面错误,然后就开始各种改,最后终于好了。。。

    错误信息如下:

    

    我百度了一下,解决的主要方案如下:

    1.在IIS里,点击你源码的虚拟目录,右键-》属性-》应用程序名-》创建

    2.若IIS中没有应用程序名,先创建,若还不行把C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config中的所     allowDefinition="MachineToApplication"改为allowDefinition="Everywhere"

    3.在Web.config文件中删除<authentication mode="Windows" />结点就可以了。


   其实呢,首先你要看你的WebConfig配置文件是不是存在于你引入网站项目的根目录中不是的话一定将其移至根目录,其次看看你的网站中是否存在两个或者多个WebConfig配置文件如果有的话请删除确保网站中有且只有一个WebConfig配置文件,最后观察你的WebConfig文件中是否存在不能重复设置的结点而你设置了多次检查后剔除。

    希望可以帮到大家。

<?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="DB-NetShopsConnectionString" connectionString="Data Source=.\MSSQLSERVER2012;Initial Catalog=DB-NetShops;User ID=sa;Password=your_password;Integrated Security=False" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <!-- 添加全局cookie设置 --> <httpCookies httpOnlyCookies="true" /> <compilation debug="true" targetFramework="4.7.2" /> <httpRuntime targetFramework="4.7.2" maxRequestLength="20480" executionTimeout="300" requestValidationMode="4.7.2" /> <!-- 移除httpOnlyCookies属性 --> <sessionState mode="InProc" timeout="20" /> <authentication mode="Forms"> <!-- 移除httpOnlyCookies属性 --> <forms loginUrl="~/WebForm1.aspx" defaultUrl="~/WebForm2.aspx" timeout="20" /> </authentication> <globalization culture="zh-CN" uiCulture="zh-CN" requestEncoding="utf-8" responseEncoding="utf-8" /> <customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx"> <error statusCode="404" redirect="~/404.aspx" /> <error statusCode="500" redirect="~/500.aspx" /> </customErrors> <pages masterPageFile="~/Site.master"> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> </controls> </pages> </system.web> <system.webServer> <httpProtocol> <customHeaders> <add name="X-Content-Type-Options" value="nosniff" /> <add name="X-Frame-Options" value="SAMEORIGIN" /> <add name="X-Xss-Protection" value="1; mode=block" /> </customHeaders> </httpProtocol> <staticContent> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" /> </staticContent> <security> <requestFiltering> <requestLimits maxAllowedContentLength="20971520" /> </requestFiltering> </security> </system.webServer> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /> </compilers> </system.codedom> </configuration> 添加母版页代码设置,生成完整webconfig代码
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值