积极答复者
关于认证失败后错误画面的问题

问题
答案
-
你好,请参考
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/GenericErrorPage.htm">
......
<error statusCode="403" redirect="~/ErrorPages/NoAccess.htm"/>
<error statusCode="404" redirect="~/ErrorPages/FileNotFound.htm"/>
</customErrors>
jon.valett@gmail.com- 已标记为答案 KeFang Chen 2009年8月26日 2:21
-
context.Response.StatusCode = 401;应该只是将StatusCode设置成401而已~对输出内容似乎并不会有改变~
我和 Snowdream 版主的想法一样,你可以 StatusCode 做为方法的返回值,比如 0 为成功, 其它为错误代码,验证页面获取到这个值根据你的需要使用 Response.Redirect 跳转到指定页面。
宠辱不惊,看庭前花开花落。去留无意,望天上云卷云舒。
知识改变命运,奋斗成就人生!- 已建议为答案 mldark 2009年8月25日 13:42
- 已标记为答案 KeFang Chen 2009年8月26日 2:21
全部回复
-
你好,请参考
<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorPages/GenericErrorPage.htm">
......
<error statusCode="403" redirect="~/ErrorPages/NoAccess.htm"/>
<error statusCode="404" redirect="~/ErrorPages/FileNotFound.htm"/>
</customErrors>
jon.valett@gmail.com- 已标记为答案 KeFang Chen 2009年8月26日 2:21
-
To Snowdream:
你好。是放在最外层的的。而且该文件中设置的"defaultRedirect="DefaultErrorPage.htm"就没有问题。
To X.X.Y:
你好。具体情况是我想在用户验证不通过时显示一个错误页面,代码如下:
// Extract the basic authentication credentials from the request if (!ExtractBasicCredential(authorizationHeader, ref userName, ref passWord, ref domainName)) { context.Response.StatusCode = 401; return; } // Validate the user credentials if (!ValidateCredential(userName, passWord, domainName)) { context.Response.StatusCode = 401; return; }
然后在 web.config 中有:
<customErrors mode="RemoteOnly" defaultRedirect="DefaultErrorPage.htm">
<error statusCode="401" redirect="Unauthenticated.htm"/>
</customErrors> -
context.Response.StatusCode = 401;应该只是将StatusCode设置成401而已~对输出内容似乎并不会有改变~
我和 Snowdream 版主的想法一样,你可以 StatusCode 做为方法的返回值,比如 0 为成功, 其它为错误代码,验证页面获取到这个值根据你的需要使用 Response.Redirect 跳转到指定页面。
宠辱不惊,看庭前花开花落。去留无意,望天上云卷云舒。
知识改变命运,奋斗成就人生!- 已建议为答案 mldark 2009年8月25日 13:42
- 已标记为答案 KeFang Chen 2009年8月26日 2:21