Du får inte kalla din klass för Global tror jag.
Frågan#1
Hej
Jag har en webbapplikation i C# .NET 2.0 som använder Forms authentication. Jag använder mig av Global.asax för att ta hand om själva login requesten.
Applikationen kompileras utan varningar och fungerar. Men när jag väljer Refactor > Encapsulate Fields så får jag compiler error när den kollar referenser.
Det är just global.asax som den klagar på.
The type 'Global' is defined in an assembly but not referenced. You must ad a reference.
Can not convert to type System.Web.HttpAplication to 'ASP'.global.asax
Här är ming global.asax
<%@ Application Language="C#" Inherits="InheritingHttpApplication.Global"%>
Här är Global.cs som ligger i App_Code mappen
using System;
using System.Web;
using System.Web.Security;
using System.Configuration;
using System.Security.Principal;
namespace InheritingHttpApplication
{
public class Global : System.Web.HttpApplication
{
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
// Get the stored user-data, in this case, our roles
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new GenericPrincipal(id, roles);
}
}
}
}
}
}
Någon som vet varför jag får dessa meddelanden och om jag kan göra något för att få bort dem?