'error CS0103: The name 'UserContext' does not exist in the current context
I have inherited an ASP.Net 2.0 Web application built in VS 2005 and am trying to port it to VS 2017 and Framework 4.8. In a class that is trying to determine if the user is authorized to access the system it is erroring with "error CS0103: The name 'UserContext' does not exist in the current context" and when I am in the debug mode and evaluating the line where the error is occurring the UserContext essentially does not know who the user is (me in this case) at all. I assume that it is something wrong with the web.config file settings or something. Am I missing something in the web.config file perhaps? Do I need to change the use of the UserContext to something else for Framework 4.0?
using System;
using CoreServices; //CoreServices is a webservice
.... partial class code where authentication check is being called ....
public static void InitUserContext()
{
if (UserContext.Current.Initialized)
return;
UserDTO user = null;
CoreService proxy = new CoreService();
DataContractUserDTO result = proxy.UserByLogin(UserContext.Current.GetLogin()); /// Code is erroring here
if (!result.Success)
{
if (result.CriticalError)
GotoErrorPage(result.ErrorMessage);
user = new UserDTO();
user.FullName = UserContext.Current.GetFullName();
user.Login = UserContext.Current.GetLogin();
DataContractOfFLRTUserDTO userResult = proxy.CreateUser(user);
if (!userResult.Success)
{
if (userResult.CriticalError)
GotoErrorPage(userResult.ErrorMessage);
}
user = userResult.Data[0];
}
else
user = result.Data[0];
string roles = (string.IsNullOrEmpty(user.Roles) ? "" : user.Roles);
UserContext.Current.InitContext(user.UserID.Value, user.FullName, roles);
}
//***************************************************
CoreServices method being called from above:
//***************************************************
[WebMethod(Description = "Find a user by login")]
public DataContract<UserDTO> UserByLogin(string login)
{
try
{
App.Data.UserData data = new App.Data.UserData(database);
UserDTO[] result = data.SearchBy(null, null, null, login, null);
return new DataContract<UserDTO>(result);
}
catch (DataException de)
{
return new DataContract<UserDTO>(de.Message);
}
catch (Exception ex)
{
return new DataContract<UserDTO>(ex);
}
}
//***************************************************
webConfig:
//***************************************************
<?xml version="1.0"?>
<configuration>
<connectionStrings/>
<system.web>
<sessionState mode="InProc" timeout="3000"/>
<compilation debug="true" targetFramework="4.8">
<assemblies>
<add assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Shared, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Drawing.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
<authentication mode="Windows"/>
<customErrors mode="Off" />
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<location allowOverride="true">
<appSettings>
<add key="CoreServices.CoreService" value="http://localhost:7777/App.WEBSERVICE/CoreService.asmx"/>
</appSettings>
</location>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network host="localhost" port="25" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
<system.webServer>
<handlers>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>
</handlers>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
Solution 1:[1]
After further investigation this an issue much deeper in the solution with some flawed logic in the code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Edward |
