当用户请求不存在的页面时,我试图从Web配置重定向404页面。 This是我的网络配置。
当我尝试它时,重定向不起作用,我得到IIS默认的404页面。我在我的本地IIS Express上尝试它。
this是我的页面列表.404页面位于根目录。
我该怎么做?
答案 0 :(得分:0)
IIS不是很好。 (免责声明)
为了让IIS知道你在做什么并实际显示你的自定义404页面,页面本身必须超过一定的字节大小(确切地说是512 bytes
),否则IIS假定它知道更好并显示它的默认值404。
尝试在404页面底部添加注释掉的行以“膨胀”一点。听起来很疯狂,我知道,但它确实有效。
编辑:512 bytes
我认为是最小页面大小,否则IIS会跳过它。我确信M $有人认为这是个好主意。
答案 1 :(得分:0)
错误状态代码404设置重定向到“〜/ 404.aspx”这应该可以解决问题。
如果仍然无效,请尝试以下操作:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="~/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
将上面的代码放在web.config中的system.webServer标记内。
IIS Express使用system.webserver,因为它基于IIS7代码库: http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx
请告诉我它是否有效。
问候。
答案 2 :(得分:0)
查看你的web.config条目让我怀疑你的错误页面404.aspx本身是否是你看到404错误的原因。可能会删除/ from redirect =“/ 404.aspx”就可以了。使用一些开发工具分析您的请求。
答案 3 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<location path="index.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="~/Admin/Login.aspx" exactDestination="true" httpResponseStatus="Found" />
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
</location>
<location path="images">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="js">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Resimler">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Script">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Scripts">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<system.web>
<customErrors mode="On" defaultRedirect="~/Hata.aspx">
<error statusCode="404" redirect="~/404.aspx"/>
</customErrors>
<pages validateRequest="false">
<controls>
<add tagPrefix="CKEditor" assembly="CKEditor.NET" namespace="CKEditor.NET"/>
</controls>
</pages>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="Admin/Login.aspx" defaultUrl="Default.aspx" protection="All" timeout="30" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" ticketCompatibilityMode="Framework20">
<credentials passwordFormat="SHA1">
<user name="admin" password="7dc959a7d6440baa02e0bb84b1dffeb173facf5a" />
</credentials>
</forms>
<passport redirectUrl="internal" />
</authentication>
<httpRuntime targetFramework="4.5" requestValidationMode="2.0" executionTimeout="1200" maxRequestLength="51200" />
</system.web>
<connectionStrings>
<add name="InsaatEntities" connectionString="metadata=res://*/ModelInsaat.csdl|res://*/ModelInsaat.ssdl|res://*/ModelInsaat.msl;provider=System.Data.SqlClient;provider connection string="data source=mssql03.natro.com;initial catalog=DB120807190835;persist security info=True;user id=USR120807190835;password=PSS!H3Z7F1%;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="ModelInsaatEntitiy" connectionString="metadata=res://*/ModelInsaat.csdl|res://*/ModelInsaat.ssdl|res://*/ModelInsaat.msl;provider=System.Data.SqlClient;provider connection string="data source=mssql03.natro.com;initial catalog=DB120807190835;persist security info=True;user id=USR120807190835;password=PSS!H3Z7F1%;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="DB120807190835Entities" connectionString="metadata=res://*/ModelInsaat.csdl|res://*/ModelInsaat.ssdl|res://*/ModelInsaat.msl;provider=System.Data.SqlClient;provider connection string="data source=mssql03.natro.com;initial catalog=DB120807190835;persist security info=True;user id=USR120807190835;password=PSS!H3Z7F1%;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="ModelInsaatEntities" connectionString="metadata=res://*/ModelInsaat.csdl|res://*/ModelInsaat.ssdl|res://*/ModelInsaat.msl;provider=System.Data.SqlClient;provider connection string="data source=mssql03.natro.com;initial catalog=DB120807190835;persist security info=True;user id=USR120807190835;password=PSS!H3Z7F1%;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
这是我的网络配置。当我请求nonexist.aspx时,它正确地重定向页面404.aspx,但是当我请求没有.aspx扩展名的mydomain / nonexists时,它重定向默认的iis 404页面。我的页面大小是超过512字节