c# - ASP.Net : Authorization issue

标签 c# asp.net url-rewriting forms-authentication asp.net-4.0

我在配置授权规则时使用 ASP .Net 4 的 URL 路由功能时遇到了一些问题。

Global.asax

void Application_Start(object sender, EventArgs e) {
    RegisterRoutes(RouteTable.Routes);
}

private void RegisterRoutes(RouteCollection routes) {
    routes.MapPageRoute("dashboard", "", "~/Restricted/Default.aspx", true);
    routes.MapPageRoute("register", "register", "~/Register.aspx", true);
    routes.MapPageRoute("login", "login", "~/Login.aspx", true);
}

{Root}\Web.Config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <authentication mode="Forms">
            <forms name="DevAuth" 
                   loginUrl="/login/" 
                   protection="All" 
                   path="/" 
                   timeout="15"
                   requireSSL="false" 
                   slidingExpiration="true" 
                   cookieless="AutoDetect" />
        </authentication>
    </system.web>
    <system.webServer>
        <security>
            <authentication>
                <basicAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
</configuration>

{Root}\Restricted\Web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <authorization>
                <remove users="*" roles="" verbs="" />
                <add accessType="Allow" roles="Developer" />
                <add accessType="Deny" users="*" />
            </authorization>
        </security>
    </system.webServer>
</configuration>

我面临的问题是:

知道发生了什么吗?

编辑 1

配置文件中的以下更改使我访问被拒绝。

{Root}\Web.Config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <authentication mode="Forms">
            <forms name="DevAuth" 
                   loginUrl="/login/" 
                   protection="All" 
                   path="/" 
                   timeout="15"
                   requireSSL="false" 
                   slidingExpiration="true" 
                   cookieless="AutoDetect" />
        </authentication>
    </system.web>
    <system.webServer>
        <security>
            <authentication>
                <basicAuthentication enabled="false" />
            </authentication>
        </security>
    </system.webServer>
    <location path="login">
        <system.web>
            <authorization>
                <allow users="*"/>
            </authorization>
        </system.web>
    </location>
    <location path="register">
        <system.web>
            <authorization>
                <allow users="*"/>
            </authorization>
        </system.web>
    </location>
    <location path="">
        <system.web>
            <authorization>
                <deny users="*"/>
            </authorization>
        </system.web>
    </location>
</configuration>

最佳答案

嗯,我认为它是围绕着这个而来的:

<location path="">
    <system.web>
        <authorization>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>

我在这里看到的问题来自这个 path="",因为这个信息告诉 UserAgent [浏览器,比如 IE 或 FF 或 Chrome] 阻止这个地址:http://localhost:xxxxx

事实上,它指向您的默认路由:~/Restricted/Default.aspx

您默认拒绝所有用户访问此页面。希望它能为您提供有关如何执行此操作的提示。

关于c# - ASP.Net : Authorization issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3813056/

相关文章:

c# - 如何查找文件 MyFile.03 是否位于文件夹 MyTmpFolder 中?

c# - 字典值作为不同的键

c# - 在 C# 中将结构体指针作为参数传递

javascript - Angular 斜线被编码

C#线程图像处理

jquery - 使用 jQuery Validate 进行验证并执行 AJAX 调用以返回部分 View

c# - 如何将 Dictionary 对象传递给泛型类型参数?

asp.net - CSS 列表奇怪的行为

url-rewriting - 在 IIS 7.5 上的 Mediawiki URL 中显示冒号

.htaccess - 为 N 个查询字符串重写 url