在ASP.NET 2.0 WebForms中使用UrlRewrite时如何优雅地处理ReturnUrl [英] How to elegantly handle ReturnUrl when using UrlRewrite in ASP.NET 2.0 WebForms

查看:123
本文介绍了在ASP.NET 2.0 WebForms中使用UrlRewrite时如何优雅地处理ReturnUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,其中包含多个我希望限制访问的.aspx页面.我已使用<deny users="?"/>将web.config添加到该文件夹​​.

I have a folder with multiple .aspx pages that I want to restrict access to. I have added web.config to that folder with <deny users="?"/>.

问题是当我使用UrlRewrite时,ReturnUrl是使用.aspx文件的物理路径自动生成的.

The problem is that ReturnUrl is auto-generated with physical path to the .aspx file while I'm using UrlRewrite.

是否有一种无需手动进行身份验证检查和重定向即可操作ReturnUrl的方法?有没有办法从后台代码或从web.config设置ReturnUrl?

Is there a way to manipulate ReturnUrl without doing manual authentication check and redirection? Is there a way to set ReturnUrl from code-behind or from web.config?

编辑:该应用程序正在使用ASP.NET 2.0 WebForms.我不能使用3.5路由.

EDIT: The application is using ASP.NET 2.0 WebForms. I cannot use 3.5 routing.

编辑2 :似乎从未捕获到401状态代码.它为受保护页面返回302,并使用ReturnUrl重定向到登录页面.对于受保护的页面,它不会返回401.嗯...有趣...参考: http://msdn.microsoft. com/en-us/library/aa480476.aspx

EDIT 2: It seems like 401 status code is never captured. It returns 302 for protected page and redirects to login page with ReturnUrl. It does not return 401 for protected page. Hmm... Interesting... Ref: http://msdn.microsoft.com/en-us/library/aa480476.aspx

这使事情变得更难...我可能必须编写反向重写映射规则以使正则表达式匹配ReturnUrl,如果不返回401则将其替换...如果确实返回401,则可以将RawUrl设置为Response.RedirectLocation或用RawUrl替换ReturnUrl.

This makes things harder... I might have to write reverse rewrite mapping rules to regex match ReturnUrl and replace it if it doesn't return 401... If it does return 401 I can either set RawUrl to Response.RedirectLocation or replace ReturnUrl with RawUrl.

还有其他想法吗?

推荐答案

我最终检查了URL中是否存在ReturnUrl,并在Global.asax的EndRequest阶段中将其替换为RawUrl.暂时对我有效...

I ended up checking for existence of ReturnUrl in the Url and replacing it with RawUrl in EndRequest stage in Global.asax. This works for me for now...

这篇关于在ASP.NET 2.0 WebForms中使用UrlRewrite时如何优雅地处理ReturnUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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