web.config中
<authentication mode="Forms"> 
       <forms loginUrl="Register/Login.aspx" name="AuthCookie" path="/" protection="All"/>
    </authentication>
<location path="ResourcePub/aaa">
             <system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
    </location>
Global.asax.cs:                     
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName]; if(null == authCookie)
{
return;
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch(Exception ex)
{ return;
} if (null == authTicket)
{ return; 
}
string[] roles = authTicket.UserData.Split(new char[]{'|'});

FormsIdentity id = new FormsIdentity( authTicket ); 
GenericPrincipal principal = new GenericPrincipal(id, roles);

Context.User = principal;
                   }
Login.aspx.cs
   
string roles="管理员";FormsAuthenticationTicket authTicket= new FormsAuthenticationTicket(1,this.UserName .Text,DateTime.Now ,DateTime.Now .AddMinutes (60),false,roles);string encryptedTicket = FormsAuthentication.Encrypt (authTicket);HttpCookie authCookie=new HttpCookie(FormsAuthentication.FormsCookieName ,encryptedTicket);Response.Cookies .Add (authCookie);Response.Redirect (FormsAuthentication.GetRedirectUrl(this.UserName .Text ,false));
===================================================================
 
FormsAuthentication.GetRedirectUrl(this.UserName .Text ,false)并没有得到我开始请求的Url
而是得到default.aspx,这是怎么回事啊??请大家帮帮忙!!!

解决方案 »

  1.   

    <location path="ResourcePub/aaa">
                 <system.web>
    <authorization>
    <deny users="?" />
    </authorization>
    </system.web>
        </location>
    只是说ResourcePub/aaa不允许匿名,其他的路径呢?
      

  2.   

    <authorization>
            <allow users="*" /> <!-- 允许所有用户 -->  
      </authorization>
    其他就可以啊
      

  3.   

    我是在default.aspx页面有
    <a href="ResourcePub/aaa/generalinf.aspx" target=_blank >generalinf</a>
    default.aspx也是起始页
    点击链接generalinf,因为不允许匿名所以来到Register/Login.aspx,登陆
      

  4.   

    http://community.csdn.net/Expert/TopicView3.asp?id=5223021