webForumDet fria alternativet

Skumt kompileringsfel

.NET

1 svar · 373 visningar · startad av Addeladde

Medlem sedan jan. 20013 406 inlägg
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?

Medlem sedan aug. 20003 575 inlägg
#2

Du får inte kalla din klass för Global tror jag.

263 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
124 ms — deklarationer (db)
0 ms — hämta statistik (cache)
133 ms — hämta tråd, inlägg och bilagor (db)
125 ms — ändringar (db)