2012-09-22 20 views

回答

0

您可以使用此 - 基於location attribute

<configuration> 
    <location path="SecuredWebForm.aspx"> 
     <system.web> 
     <authorization> 
      <allow users="..."/> 
     </authorization> 
     </system.web> 
    </location> 
</configuration> 

諾塔:您調整用戶的價值

鏈接:http://msdn.microsoft.com/en-us/library/b6x6shw7%28v=vs.71%29.aspx

如果您有安全架構,您可以使用IsAuthenticated財產

鏈接:http://msdn.microsoft.com/en-us/library/system.web.httprequest.isauthenticated.aspx

if (HttpContext.Current.User.Identity.IsAuthenticated) 
    { 
    } 
0

這將是很好用爲此目的的會員類別。如果你沒有特別的要求。

如果您已經創建了NewProject與WebApplication的,那麼VisualStudio的可能已經設置爲你的所有關注配置web.config類似以下內容:通過添加<authorization...>...</authorization>元素

編輯web.config。它將通過訪問授權內容來防止匿名用戶。

<configuration> 
    <connectionStrings> 
    <add name="ApplicationServices" connectionString="ConnectionStringData" providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

    <system.web> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> 
    </authentication> 

    <authorization> 
     <deny users="?"/> 
    </authorization> 

    <membership> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" 
      enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" 
      maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" 
      applicationName="/" /> 
     </providers> 
    </membership> 
    ... 
    ... 
    </system.web> 
    ... 
    ... 
</configuration> 

您可能還需要確保來自匿名用戶的網絡表單,那麼你可能會寫以下內容:

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!User.Identity.IsAuthenticated) 
     Response.Redirect("Login.aspx"); 

    // Todo add code here.   
} 
相關問題