![](/img/trans.png)
[英]How to redirect to different pages in asp.net c# (user pages and admin pages) using stored procedure
[英]Using different 404 error pages depending on URL tried by the user
(注意:我對asp.net/c#還很陌生,請多多包涵)
在我的網站上,我通過在web.config中使用此頁面來使用自定義404錯誤頁面
<customErrors mode="RemoteOnly" defaultRedirect="http://mywebsite.org/404">
<error statusCode="404" redirect="http://mywebsite.org/404" />
</customErrors>
現在,我想添加其他404頁面,這些頁面被包含某些字符串的URL“觸發”。 例如,如果URL包含/library/
我希望將用戶重定向到http://mywebsite.org/library-404
,其中包含特定於網站庫部分的信息。 包含/services/
和其他URL的URL也是如此。
能做到嗎? 如果是這樣,怎么辦? 感謝您的時間。
您可以嘗試使用ASP.NET MVC。設置“路由”以映射網址。
您可以在Global.asax.cs中定義方法Application_Error並像這樣處理
void Application_Error(object sender, EventArgs e)
{
var error = Server.GetLastError();
var code = (error is HttpException) ? (error as HttpException).GetHttpCode() : 500;
string path = Request.Path;
if (code == 404)
{
if (new Regex(@"\/library\/", RegexOptions.IgnoreCase).IsMatch(path))
{
Server.ClearError();
Response.Redirect(String.Format("~/Library/Error404"));
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.