且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何阻止对特定aspx页面的直接URL访问

更新时间:2023-12-02 10:25:28

在这种情况下使用404将破坏http标准。正如评论中所建议的,只是代码直接访问页面的情况。



在页面上的asp:Literal中有一个错误消息,其中Visible = false然后在你的代码背后;



Using a 404 in this situation would break http standards. As suggested in the comments simply code for the situation where the page is accessed directly.

Have an error message in an asp:Literal on the page with Visible=false then in your code behind;

If Not dataFound Then
    LiteralMyError.Visible = True
    Exit ' not sure if this is how you abort a function, I dont know vb.net
End If


Function Create() As ActionResult
       Try
           ' TODO: Add insert logic here
           Return RedirectToAction("Index")
       Catch
           Return View('Error')
           ' or redirect to your custom error page
       End Try
   End Function





如果您不使用MVC,只需编写您使用的技术,我将编辑我的答案;)



If you are not using MVC, just write technology you use and I will edit my answer ;)