希望這很簡單。我有一個相當簡單的ASP.NET(框架版本2)應用程序,它使用自定義表格進行用戶驗證。無論如何,我有兩個頁面,登錄和註冊。你可以猜測目的是什麼。用戶應該能夠通過點擊註冊鏈接來請求註冊 - 這是一個帶有提交按鈕的表單,用於執行一些數據庫調用來查看用戶是否存在等等。登錄頁面使用驗證Cookie進行驗證。我使用窗體身份驗證 - 這是我的web.config:ASP.NET - 如果來自注冊頁面,請停止重定向到登錄頁面
<authentication mode="Forms">
<forms loginUrl="logon.aspx" name="adAuthCookie" timeout="30" path="/" defaultUrl="~/logon.aspx">
</forms>
</authentication>
每次我做一個HTTP調用到註冊頁面(在http://localhost/registration.aspx鍵入IE瀏覽器 - 它重定向到登錄頁面
global.asax.cs文件有這個內容 - 這是一個身份驗證檢查,如果請求的頁面是註冊頁面,我想禁用這個檢查 - 因爲用戶不需要通過身份驗證來訪問此頁面。這個?
void Application_AuthenticateRequest(object sender, EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (null == authCookie)
{
//There is no authentication cookie.
return; // right here it will return null then redirect to login.aspx
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch (Exception ex)
{
//Write the exception to the Event Log.
return;
}
if (null == authTicket)
{
//Cookie failed to decrypt.
return;
}
//When the ticket was created, the UserData property was assigned a
//pipe-delimited string of group names.
string[] groups = authTicket.UserData.Split(new char[] { '|' });
//Create an Identity.
GenericIdentity id = new GenericIdentity(authTicket.Name, "LdapAuthentication");
//This principal flows throughout the request.
GenericPrincipal principal = new GenericPrincipal(id, groups);
Context.User = principal;
}
您能通過字符串比較檢查,如果請求的URL包含字符串「註冊」,而不是返回 – rt2800 2012-04-23 14:31:17
檢查這個http://stackoverflow.com/questions/3628445/允許訪問未認證用戶對特定頁面使用asp-net-forms-authe – Aristos 2012-04-23 14:36:01