簡體   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