捕获无效的网址 [英] Trapping for invalid URLs

查看:60
本文介绍了捕获无效的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我继承了一个ASP.NET网络应用程序,我希望将其重组为更多

逻辑文件夹层次结构(超过150个)应用程序根目录中的WebForms,但很多

用户通过他们已经添加到他们的

收藏夹中的完全限定的URL访问该网站。 />

有没有办法在页面请求被处理之前捕获它以便我可以将
重定向到新文件夹结构中的位置?例如。用户试图获得
访问权限:

http://www.mysite.com/viewmonthlystats.aspx


但该页面现在位于

http://www.mysite.com/stats/monthly/view.aspx


我希望我可以在
Global.asax中使用Application_BeginRequest做一些事情,但是在我调用它之前我得到了404错误。 />

Mark

Hi,

I''ve inherited an ASP.NET web app which I want to restructure into a more
logical folder hierarchy (over 150 WebForms in the app''s root), but lots of
users access the site by fully-qualified URLs which they''ve added to their
Favourites.

Is there any way to trap a page request before it''s processed so that I can
redirect to its location in the new folder structure? E.g. user tries to
access:

http://www.mysite.com/viewmonthlystats.aspx

but that page now resides in

http://www.mysite.com/stats/monthly/view.aspx

I''d hoped that I could do something with Application_BeginRequest in
Global.asax, but I get the 404 error before that is even invoked.

Mark

推荐答案

Mark,


最简单的方法做你想要的是实现自定义HTTP

处理程序。在您这样做之前,我建议您在下面的文章中看看



http://msdn.microsoft.com/library/de...lrewriting .asp


它讨论并提供URL重写的解决方案。


sayed


" Mark Rae" <毫安** @ mark-N-O-S-P-A-M-rae.co.uk>在消息新闻中写道:< OR ************** @ TK2MSFTNGP12.phx.gbl> ...
Mark,

The easiest way to do what you want is to implement a custom HTTP
Handler. Before you do that though, I recommend that you have a look
at the following article.

http://msdn.microsoft.com/library/de...lrewriting.asp

It discusses, and provides a solution for, URL rewriting.

sayed


"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message news:<OR**************@TK2MSFTNGP12.phx.gbl>...


我已经继承了一个ASP.NET网络应用程序,我希望将其重组为更合理的逻辑文件夹层次结构(应用程序根目录中的150多个WebForms),但许多用户访问该网站通过他们已经添加到他们的收藏夹中的完全限定的URL。

是否有任何方法可以在页面请求被处理之前捕获它以便我可以
重定向到新文件夹结构中的位置?例如。用户尝试访问:

http:/ /www.mysite.com/viewmonthlystats.aspx

但该页面现在位于

http://www.mysite.com/stats/monthly/view.aspx

我'我希望我可以在Global.asax中使用Application_BeginRequest做一些事情,但是在调用它之前我得到了404错误。

Mark
Hi,

I''ve inherited an ASP.NET web app which I want to restructure into a more
logical folder hierarchy (over 150 WebForms in the app''s root), but lots of
users access the site by fully-qualified URLs which they''ve added to their
Favourites.

Is there any way to trap a page request before it''s processed so that I can
redirect to its location in the new folder structure? E.g. user tries to
access:

http://www.mysite.com/viewmonthlystats.aspx

but that page now resides in

http://www.mysite.com/stats/monthly/view.aspx

I''d hoped that I could do something with Application_BeginRequest in
Global.asax, but I get the 404 error before that is even invoked.

Mark



" Sayed Hashimi" <公顷*********** @ hotmail.com>在消息中写道

news:3a ************************** @ posting.google.c om ...


Sayed,
"Sayed Hashimi" <ha***********@hotmail.com> wrote in message
news:3a**************************@posting.google.c om...

Sayed,
最简单的方法就是实现自定义HTTP
处理程序。在你这样做之前,我建议你看看下面的文章。

http://msdn.microsoft.com/library/de...lrewriting.asp

它讨论并提供URL重写的解决方案。
The easiest way to do what you want is to implement a custom HTTP
Handler. Before you do that though, I recommend that you have a look
at the following article.

http://msdn.microsoft.com/library/de...lrewriting.asp

It discusses, and provides a solution for, URL rewriting.




感谢您的回复 - 我先查看了这篇文章但是由于最后的警告,在这种情况下,没有想到它会给我带来帮助。


当然,使用ASP.NET级别重写,如果请求是成功从IIS传递到ASP.NET引擎的
,则只能进行URL重写

。当用户

请求具有.aspx扩展名的页面时,会自然发生这种情况。但是,如果你想让这个人能够输入一个可能实际上并不存在的

网址,而是想改写现有的

ASP.NET页面,你需要创建模拟目录和Default.aspx页面,或者配置

IIS以便所有传入

请求被盲目地路由到ASP.NET引擎。


我不能在这个实例中重新配置IIS,因为它的公共站点是

托管有一个商业ISP,可以理解的是,不允许这样做。我知道我可以离开网站的根目录,里面装满了小小的

HTML文件,除了重定向到
中的等效页面之外什么都不做
拟议的新层次结构,但是如果

所有可能的话,我很想避免这种情况。



Thanks for the reply - I checked this article out first but didn''t think it
would help me in this instance, due to the caveat at the end:

"Of course, with ASP.NET-level rewriting, the URL rewriting can only happen
if the request is
successfully handed off from IIS to the ASP.NET engine. This naturally
occurs when the user
requests a page with a .aspx extension. However, if you want the person to
be able to enter a
URL that might not actually exist, but would rather rewrite to an existing
ASP.NET page, you
have to either create mock directories and Default.aspx pages, or configure
IIS so that all incoming
requests are blindly routed to the ASP.NET engine."

I can''t reconfigure IIS in this instance because its a public site being
hosted with a commercial ISP who, understandably, won''t allow this. I
realise that I could leave the site''s root directory full of tiny little
HTML files which do nothing other than redirect to the equivalent page in
the proposed new hierarchical structure, but was keen to avoid this if at
all possible.


Application_BeginRequest *是*你在哪里应该这样做。我有几个网站

网站使用网址不存在的页面。例如,
http://mysite.com/mynewsstory.aspx
http://mysite.com/content/content .aspx?storyid = 13


这样的东西对你有用。

Sub Application_BeginRequest(ByVal sender As Object,ByVal e As EventArgs)

''在每个请求开始时触发

尝试

''获取用户发布的实际网址

Dim strPath as String = Request.RawUrl

Dim strMyNewPath as String =""

''你的工作在这里将网址更改为

''你真正想要的路径

''...

Context.RewritePath(strMyNewPath)


Catch ex As Exception

''你的异常处理程序在这里

HandleException()

结束尝试

结束子


HTH

Craig


" Mark Rae" <毫安** @ mark-N-O-S-P-A-M-rae.co.uk>在消息中写道

news:OR ************** @ TK2MSFTNGP12.phx.gbl ...
Application_BeginRequest *is* where you should do this. I have several web
sites that use urls for pages that don''t exist. For example,
http://mysite.com/mynewsstory.aspx for
http://mysite.com/content/content.aspx?storyid=13.

Something like this should work for you.
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'' Fires at the beginning of each request
Try
'' get the actual url posted by the user
Dim strPath as String = Request.RawUrl
Dim strMyNewPath as String = ""
'' Do your work here to change the url to
'' the path you really want
'' ...
Context.RewritePath(strMyNewPath)

Catch ex As Exception
'' your exception handler here
HandleException()
End Try
End Sub

HTH
Craig

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:OR**************@TK2MSFTNGP12.phx.gbl...

我继承了一个ASP.NET网络应用程序,我希望将其重组为更合理的逻辑文件夹层次结构(应用程序根目录中超过150个WebForms),但是很多
用户通过他们已添加到他们的收藏夹中的完全限定的URL访问该站点。

是否有任何方法可以在处理页面请求之前将其捕获,以便我
可以重定向到新文件夹结构中的位置吗?例如。用户尝试访问:

http:/ /www.mysite.com/viewmonthlystats.aspx

但该页面现在位于

http://www.mysite.com/stats/monthly/view.aspx

我我希望我可以在Global.asax中使用Application_BeginRequest做一些事情,但在调用之前我得到404错误。

Mark
Hi,

I''ve inherited an ASP.NET web app which I want to restructure into a more
logical folder hierarchy (over 150 WebForms in the app''s root), but lots of users access the site by fully-qualified URLs which they''ve added to their
Favourites.

Is there any way to trap a page request before it''s processed so that I can redirect to its location in the new folder structure? E.g. user tries to
access:

http://www.mysite.com/viewmonthlystats.aspx

but that page now resides in

http://www.mysite.com/stats/monthly/view.aspx

I''d hoped that I could do something with Application_BeginRequest in
Global.asax, but I get the 404 error before that is even invoked.

Mark



这篇关于捕获无效的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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