4

I have declared a namespace in Feed.aspx.cs . This namespace contains a class and this class contains a method: Feed.aspx.cs

namespace GetUser { public class MyFeedClass { public string getUserID() { MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name); HttpContext.Current.Session["x"] = user.ProviderUserKey.ToString(); string test = (string)HttpContext.Current.Session["x"]; return test; } } 

}

Now, from MyPage.aspx.cs, I'd like to call the getUserID() method. How can I do that?

0

2 Answers 2

5

I guess you are using Asp.NET?

You should create a new class inside your add_code folder. Move that namespace and the class inside the new created class

Then call it from your Feed.aspx.cs:

GetUser.MyFeedClass myfeed = new GetUser.MyFeedClass(); string result = myfeed.getUserID(); 
Sign up to request clarification or add additional context in comments.

5 Comments

Yes, and this error pops up: The type or namespace name 'GetUser' could not be found (are you missing a using directive or an assembly reference?)
Do not declare the namespace and the class inside the aspx.cs, create a new class inside the app_code folder
@TudorGafiuc, In addition, your application will be better structured declaring your classes out for the aspx files.
Thanks Carlos, I will definetly post more questions in the future, as I'm trying to build a mini social network for my license project. Cheers!
@TudorGafiuc. Stackoverflow rocks!. See you around ;)
0

Make sure you include the namespace in your code-behind:

using GetUser; 

Make the public function a static one in the MyFeedClass:

public static string getUserID() {...} 

Then in your aspx.cs page you can now try to do:

string userId = MyFeedClass.getUserID(); 

1 Comment

I tried with "using GetUser;" and it was showing the same error - "The type or namespace name 'GetUser' could not be found". I worked it out with the above suggestions :) thanks anyway!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.