如何阻止对特定aspx页面的直接URL访问 [英] How to block direct URL access to specific aspx page

查看:151
本文介绍了如何阻止对特定aspx页面的直接URL访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个aspx页面的网站。



其中一个页面用于显示上一页提取的数据。



因此,当用户通过输入url尝试访问此特定网页时,它显然会显示代码错误。



I不希望向用户显示任何代码错误,但错误页面如错误404:未找到或页面无法显示错误页面。



As这个特定的页面获取从上一页输入的数据,从输入的URL中访问时没有数据输入肯定会出错。



所以请帮我搞清楚这个对我来说。



我在VB.Net上使用Visual Studio 2015







谢谢

I have a website with a number of aspx pages.

And one of the pages is designed to display the fetched data from previous page.

So when an user tries to access this particular webpage by typing url then it obviously shows error with codes.

I do not want to show any code errors to users but the error page such as "Error 404: Not Found or Page can't be displayed" error pages.

As this particular page gets data entered from previous page, there must be an error when accessing from typing url with no data input.

So please help me figuring out this for me.

I am using Visual Studio 2015 with VB.Net



Thanks

推荐答案

在这种情况下使用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 ;)


这篇关于如何阻止对特定aspx页面的直接URL访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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