繁体   English   中英

ASP .Net Web.config

[英]ASP .Net Web.config

在我的ASP .Net应用程序(不是MVC,Just ASP .Net)中,我有几个Web表单,需要限制用户直接访问多个Web页面。

但是在其他页面的应用程序链接中,根据应用程序的功能,应该能够将这些页面重定向(Response.Redirect或表单提交或获取方式),但严格不要直接在浏览器中输入url并访问它们。

我在那些页面加载事件中尝试了以下内容(其中需要限制直接访问)并且工作得很好。

if (Request.UrlReferrer == null)
{
     Response.Redirect("~/Index.aspx", true);
}

但我遇到的问题是我对ASP .Net相对较新,并想知道这是否是最好的方法。

1)。 主要是我搜索但需要知道我是否可以使用web.config文件完成此操作。 如果有人能解释web.config文件应该如何完成,那么将不胜感激...

2)。 此外,如果他在网站托管域名中输入错误的URL,我想重定向用户...为此,我在web.config中执行了以下操作,但想知道这是否正确。 谢谢...

<customErrors mode="On" defaultRedirect="~/Index.aspx">
    <error statusCode="404" redirect="~/Index.aspx" />
</customErrors>

您可以将其添加到web.config文件以限制特定用户:

<authorization>
<allow users="user1, user2"/>
<deny users="?"/>
</authorization>

<location path="AccessDenied.aspx">
 <system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>

在C#上,您可以使用Response.Redirect

protected void Application_EndRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.Response.Status.StartsWith("401"))
    {
        HttpContext.Current.Response.ClearContent();
        Response.Redirect("AccessDenied.aspx");
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM