我现在正在处理一些遗留代码,我正在尝试将 Global.asax 文件移动到父应用程序,它将管理所有子应用程序。目前我们在所有子应用程序中都有一个 Global.asax 文件(坏)。
当我尝试从子应用程序中删除 Global.asax 文件时,不幸的是它找不到父应用程序的 Global.asax 文件。因此,我无法在子应用程序中保持身份验证。我想知道是否有一个简单的解决方法。
结构:
parent app
files...
childapp
files..
global.asax
global.asax
我希望 childapp 找到父母的 Global.asax 文件。
多谢你们!
编辑:
全球.asax
(这在父应用程序和子应用程序中是相同的)
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
public 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;
}
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;
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}