如何在点击错误链接时重定向到页面未找到页面 [英] how to redirect to page not found page on click of wrong link

查看:67
本文介绍了如何在点击错误链接时重定向到页面未找到页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有用户的链接设施..用户可以输入链接并显示它..如果该链接不存在或无效意味着不包含htttp://那么用户应该重定向到404页面未找到页面或显示弹出窗口...如何操作?

i have link facility for users on page..users can enter link and disply it..if that link is not present or not valid means not contains "htttp://" then user should redirect to 404 page not found page or show popup..how to do it?

推荐答案

添加另一个控制器操作方法,它将异常作为参数。

从每个链接单击操作将逻辑放入try catch块并捕获异常并在catch中:

Add another Controller Action Method, that would take exception as parameter.
From each link click action put the logic in try catch block and catch the exception and inside the catch :
try{
//code goes here...
}
catch(Exception ex)
{
    if(es.Message == "check for the message matching http:404")
       {
          return RedirectToAction("NotFound");
       }
}

public ActionResult NotFound()
{
    return View();
}





希望这有帮助

谢谢

:)



Hope this helps
Thanks
:)


参考:





http://www.asp.net/web-forms/tutorials/deployment/部署-web-site-projects / displays-a-custom-error-page-cs [ ^ ]


这篇关于如何在点击错误链接时重定向到页面未找到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆