2016-04-01 94 views
0

我在表單認證的網站上的Web配置文件中具有以下內容,但它不允許用戶導航到該頁面,除非他們登錄。Web配置允許用戶不工作

<configuration> 
    <connectionStrings> 
    <remove name="******"/> 
    <add name="*******" *******"/> 
    <add name="*****" *******"/> 
    </connectionStrings> 
<location path="About.aspx"> 
    <system.web> 
     <authorization> 
     <allow users="*" /> 
     </authorization> 
    </system.web> 
    </location> 

ASP.net web forms 4 site。注意***隱藏原始數據

回答

0

您的問題是不明確的。但是再從認證通過加入這一行

<system.web> 
    <!--Session state Time Out--> 
    <sessionState timeout="60" /> 
    <!--My authontication module--> 
    <authentication mode="Forms"> 
     <forms name="PROJECTNAME.ASPXAUTH" loginUrl="~/Login.aspx" protection="All" path="/" timeout="60"/> 
    </authentication> 
    <authorization> 
     <deny users="?" /> 
    </authorization> 
</system.web> 

啓用和application.If您要訪問任何特定的文件夾,然後將固定網絡創建一個文件夾,並添加Web.config文件web.cofig文件file.and

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
     <authorization> 
     <!--Defualt access grant sa=11,admin=12--> 
     <allow roles="admin"/> 
     <!--Order and case are important below--> 

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

防止其他角色的用戶的訪問比管理

並創建角色

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
         1, // Ticket version 
         Convert.ToString(user.UserID), // Username associated with ticket 
         DateTime.Now, // Date/time issued 
         DateTime.Now.AddMinutes(60), // Date/time to expire 
         false, // "true" for a persistent user cookie 
         Convert.ToString(user.RoleID), // User-data, in this case the roles 
         FormsAuthentication.FormsCookiePath);// Path cookie valid for 

        // Encrypt the cookie using the machine key for secure transport 
        string hash = FormsAuthentication.Encrypt(ticket); 
        HttpCookie cookie = new HttpCookie(
         FormsAuthentication.FormsCookieName, // Name of auth cookie 
         hash); // Hashed ticket 

        // Set the cookie's expiration time to the tickets expiration time 
        if (ticket.IsPersistent) cookie.Expires = ticket.Expiration; 

        // Add the cookie to the list for outgoing response 
        Response.Cookies.Add(cookie);