A problem is encountered in be being developed recently,Expended two days of time,Solved . eventuallySum up,Consult in order to offer everybody .
I download an Asp.net project from mailbox to this locality machine,Build fictitious list next,Open with VS,Move debug,Occurrence mistake . Next,Open Ie, input fictitious catalog, appear to visit the wrong . of folder without attributive
Get online examine a data,Saying is Aspnet this account,Without the executive attributive . of project folderAnd in the friendly key menu of my project folder,Again Without safety this one (my systematic partition is NTFS, very strange) ,With this kind of method because of this,Still did not send solve problem .
Finally,I am in C dish build folder of a DotNet,Move the project come in,The problem solves . eventually
At a loose end is dull today .Thought . of ASP.NET identity test and verifyFeel good .Stick a following code: Login.aspx HTML code
Test and verify of identity of 1%26lt;%@ Page Language=%26quot;c#%26quot; Codebehind=%26quot;02Login.aspx.cs%26quot; AutoEventWireup=%26quot;false%26quot; Inherits=%26quot; . _02Login%26quot; %%26gt; 2%26lt; ! DOCTYPE HTML PUBLIC %26quot;-//W3C//DTD HTML 4.0 Transitional//EN%26quot; %26gt; 3%26lt;HTML%26gt; 4 %26lt;HEAD%26gt; 5 %26lt;title%26gt;02Login%26lt;/title%26gt; 6 %26lt;meta Name=%26quot;GENERATOR%26quot; Content=%26quot;Microsoft Visual Studio.NET 7.1%26quot;%26gt; 7 %26lt;meta Name=%26quot;CODE_LANGUAGE%26quot; Content=%26quot;C#%26quot;%26gt; 8 %26lt;meta Name=%26quot;vs_defaultClientScript%26quot; Content=%26quot;javascript%26quot;%26gt; 9 %26lt;meta Name=%26quot;vs_targetSchema%26quot; Content=%26quot;http://schemas.microsoft.com/intellisense/ie5%26quot;%26gt; 10 %26lt;/HEAD%26gt; 11 %26lt;body MS_POSITIONING=%26quot;GridLayout%26quot;%26gt; 12 %26lt;form Id=%26quot;Form1%26quot; Method=%26quot;post%26quot; Runat=%26quot;server%26quot;%26gt; 13 %26quot;%26gt; of body of %26lt;FONT Face=%26quot; the Song Dynasty 14 %26lt;TABLE Id=%26quot;Table1%26quot; Style=%26quot;Z-INDEX: 102; LEFT: 152px; WIDTH: 446px POSITION: Absolute; TOP: 80px; HEIGHT: 72px “ 15 CellSpacing=%26quot;1%26quot; CellPadding=%26quot1%26quot Width=%26quot;446%26quot; Border=%26quot;1%26quot;%26gt; 16 %26lt;TR%26gt; 17 %26lt;TD%26gt; 18 %26lt;asp:lName of user of Abel Id=%26quot;Label1%26quot; Runat=%26quot;server%26quot%26gt; :%26lt;/asp:lAbel%26gt%26lt;/TD%26gt; 19 %26lt;TD%26gt; 20 %26lt;asp:tExtbox Id=%26quot;tbName%26quot; Runat=%26quot;server%26quot; Width=%26quot;183px%26quot;%26gt;%26lt;/asp:tExtbox%26gt;%26lt;/TD%26gt; 21 %26lt;TD%26gt; 22 ຎlt;asp:rName of user of Equiredfieldvalidator Id=”RequiredFieldValidator1″ Runat=”server” ErrorMessage=” cannot is empty!%26quot;ControlToValidate=%26quot;tbName%26quot;%26gt;%26lt;/asp:rEquiredfieldvalidator%26gt;%26lt;/TD%26gt; 23 %26lt;/TR%26gt; 24 %26lt;TR%26gt; 25 %26lt;TD%26gt; 26 %26lt;asp:lPassword of Abel Id=%26quot;Label2%26quot; Runat=%26quot;server%26quot;%26gt; :%26lt;/asp:lAbel%26gt;%26lt;/TD%26gt; 27 %26lt;TD%26gt; 28 %26lt;asp:tExtbox Id=%26quot;tbPass%26quot; Runat=%26quot;server%26quot; Width=%26quot;183px%26quot%26gt;%26lt;/asp:tExtbox%26gt%26lt;/TD%26gt; 29 %26lt;TD%26gt; 30 %26lt;asp:rPassword of Equiredfieldvalidator Id=”RequiredFieldValidator2″ Runat=”server” ErrorMessage=” cannot is empty!%26quot;ControlToValidate=%26quot;tbPass%26quot;%26gt;%26lt;/asp:rEquiredfieldvalidator%26gt;%26lt;/TD%26gt; 31 %26lt;/TR%26gt; 32 %26lt;TR%26gt; 33 Whether does %26quot;%26gt; of body of %26lt;TD%26gt;%26lt;FONT Face=%26quot; the Song Dynasty save Cookie%26lt;/FONT%26gt;%26lt;/TD%26gt; 34 %26lt;TD%26gt; 35 %26lt;asp:cHeckbox Id=%26quot;PersistCookie%26quot; Runat=%26quot;server%26quot;%26gt;%26lt;/asp:cHeckbox%26gt;%26lt;/TD%26gt; 36 %26lt;TD%26gt;%26lt;/TD%26gt; 37 %26lt;/TR%26gt; 38 %Ǻlt;/TABLE%26gt; 39 %26lt;asp:bUtton Id=”btnLoginBetter” Style=”Z-INDEX: 101; LEFT: 288px; POSITION: Absolute; TOP: 240px “ 40 Runat=%26quot;server%26quot; Width=%26quot;78px%26quot; Text=%26quot; logs onto %26quot;%26gt;%26lt;/asp:bUtton%26gt; 41 %26lt;asp:HYperLink Id=”HyperLink1″ Style=”Z-INDEX: 103; LEFT: 456px; POSITION: Absolute; TOP: 240px “ 42 Runat=%26quot;server%26quot; NavigateUrl=%26quot;Default.aspx%26quot;%26gt;HyperLink%26lt;/asp:HYperLink%26gt;%26lt;/FONT%26gt; 43 %26lt;/form%26gt; 44 %26lt;/body%26gt; 45%26lt;/HTML%26gt;Login.aspx.cs code is as follows
Private Void BtnLoginBetter_Click(object Sender, system.EventArgs E) {If (this.tbName.Text==%26quot;Admin%26quot; %26amp;%26amp;This.tbPass.Text==”Admin” ) { FormsAuthenticationTicket Ticket = New FormsAuthenticationTicket(1, this.tbName.Text, dateTime.Now, dateTime.Now.AddMinutes (30) , this.PersistCookie.Checked, “User”);// founds bill of a test and verifyString CookieStr = FormsAuthentication.Encrypt(ticket); undertakes adding close HttpCookie Cookie = New HttpCookie(FormsAuthentication.FormsCookieName, cookieStr); founds a Cookie,Cookie name is the name that Web.config installs, the value is add close the data CookieStr after, If (this.PersistCookie.Checked)// judges an user to whether choose middleman and guarantor to put CookieCookie.Expires = Ticket.Expiration// gets Cookie to expire timeCookie.Path = FormsAuthentication.FormsCookiePath;// installs Cookie to save method Response.Cookies.Add(cookie);String StrRedirect;StrRedirect = Request["ReturnUrl"];// is taken out return UrlIf (strRedirect==Null)StrRedirect = “Default.aspx”; Response.Redirect(strRedirect, true);
}Else { Response.Write(%26quot;%26lt;script%26gt;alert(‘ account or password are wrong! ‘);self.location.href=’02login.aspx’%26lt;/script%26gt;%26quot;); } }
Body of Web window is designed implement system of generated window of code #region Web is designed implement generated codeOverride Protected Void OnInit(EventArgs E) { / / / / CODEGEN: Should be being called is design of style of window of ASP.NET Web implement what need. / / InitializeComponent();Base.OnInit(e); }
/ **//// %26lt;summary%26gt; / / / design implement the method that support needs – do not use code editor to revise / / / the content of this method. / / / %26lt;/summary%26gt;Private Void InitializeComponent() { This.btnLogout.Click += New System.EventHandler(this.btnLogout_Click)This.Load += New System.EventHandler(this.Page_Load);
Webconfig is configured as follows %26lt;authentication Mode=%26quot;Forms%26quot; %26gt; %26lt;forms Name=%26quot;.SecurityDemo%26quot LoginUrl=ຎquot;login.aspx%26quot;%26gt;//.SecurityDemo is Cookie name, %26lt;/forms%26gt; %26lt;/authentication%26gt
%26lt;authorization%26gt; %26lt;deny Users=%26quot; ? “/%26gt;/ / reject all and faceless user %26lt;allow Roles=%26quot;admins%26quot;/%26gt;// allows to manage level user visit %26lt;/authorization%26gt; Find oneself ASP is written much,It is to use Session to undertake judging an user commonly lawful, but identity test and verify is used in an ASP.NET project, basically all page wants ability of test and verify to visit,Feel move having a place is strong. But limits of authority can be set to appointed page in Web.config page, setting code is as follows %26lt;location Path=%26quot;admin.aspx%26quot%26gt; %26lt;system.web%26gt %26ltauthorization%26gt; %26lt;deny Users=%26quot; ? %26quot;/ %26gt; %26lt;/authorization%26gt; %26lt;/system.web%26gt; %26lt;/location%26gt; If only a few pages install as above code, the feeling still can be accepted. But the page became much not be to want a person tired dead ah .. The likelihood is small project is done much, big project had not been contacted. Ask ace to give show specific use ah .Do not appreciate very