ASP.Net URL重写和认证 [英] ASP.Net URL rewriting and authentication

查看:128
本文介绍了ASP.Net URL重写和认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用.net 2.0框架的Web应用程序。整个网站仅限于使用Windows身份验证身份验证的用户。这些规则在web.config文件中设置以下方式:

I have a web application using the .Net 2.0 framework. The whole website is restricted to authenticated users using Windows authentication. These rules are set in the web.config file the following way :

<location path="/">
    <system.web>
        <authorization>
            <allow roles="CustomerAdministrator, Manager"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>
<location path="Path/To/Public/File.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>
[...]

如上图所示,我有一个网页,我想是公开的。到现在为止,一切工作正常。我们最近增加了URL重写更好的网址,所以我设置一个重写规则为大众页:

As shown above, I have one page that I want to be public. Up to this point, everything works fine. We recently added url rewriting for nicer urls, so I set a rewrite rule for the public page :

<RewriterConfig>
    <Rules>
        <RewriterRule>
            <LookFor>~/Public</LookFor>
            <SendTo><![CDATA[~/Path/To/Public/File.aspx]]></SendTo>
        </RewriterRule>
    </Rules>
</RewriterConfig>

现在,通过其直接访问网址公开页面时,它按预期工作(无需身份验证),但是当我试图通过其rewrited URL访问页面时,它要求进行身份验证。

Now, when accessing the public page by its direct url, it works as expected (no authentication required), but when I try to access the page through its rewrited url, it asks for authentication.

有谁知道在哪里这个问题我是从哪里来的?

Does anyone know where this problem my come from ?

推荐答案

我居然发现了这个问题。我使用的是 URLRewriter 项目我的一些同事在网上找到,并从事实,即它是在的HttpApplication <注册本身问题就来了/ code>的的AuthorizeRequest 事件。虽然这适用于表单验证,它确实没有与Windows身份验证,我使用的。

I actually found the problem. I am using an URLRewriter project some of my colleague found on the web, and the problem came from the fact that it was registering itself at the HttpApplication's AuthorizeRequest event. While this works with Forms authentication, it doesn't with Windows authentication, which I'm using.

要解决这个问题,我只是不得不改变它,这样它注册到的BeginRequest 事件,而不是(写在评论... ... RTFM)

To solve the problem, I simply had to change it such that it registers to the BeginRequest event instead (as written in the comments... RTFM...).

这篇关于ASP.Net URL重写和认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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