Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:22:25+00:00 2026-06-18T00:22:25+00:00

I need to get user id from asp.net mvc 3 app in console app.

  • 0

I need to get user id from asp.net mvc 3 app in console app. Here is my code: (mvc)

public class MembershipRepository : IMembershipRepository
{
    public Guid GetUserId(string name)
    {
        var providerUserKey = Membership.GetUser(name).ProviderUserKey; // HttpException
        if (providerUserKey != null)
            return (Guid)providerUserKey;
        throw new NullReferenceException("user with this username does't exist");
    }
}

(console) code:

ninjectKernel.Bind<IMembershipRepository>().To<MembershipRepository>();
var membershipRepository = ninjectKernel.Get<IMembershipRepository>();
Guid userId = membershipRepository.GetUserId("admin");

HttpException: Unable to connect to the Sql server database.

Before the exception occures the window pops up: This program has compatibility problems (microsoft sql seqver 2008 and 2008 r2).
I have sql server 2012 installed.

Besides, it’s only a small chunk of code. Before I’m trying to get userId I use other repositories to add data to the database and it works: when I check the table contents it’s full of new entries.

How do I need to change the code? Mabby there is some other way to get userId in console app?

Thanks!

Edits:

App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add
       name="WebStoreConnectionString" connectionString="Data Source=(LocalDB)\v11.0; DataBase=WebStore;
          AttachDbFilename=C:\Users\Aleksey\repos\working_copy\WebStore\WebStore\App_Data\WebStore.mdf;
          Integrated Security=True;Connect Timeout=30"
          providerName="System.Data.SqlClient"
    />
 </connectionStrings>
</configuration>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:22:26+00:00Added an answer on June 18, 2026 at 12:22 am

    The exception occured because in MembershipRepository I used built-in Membership provider to return Users. I changed the impementation to work with data context:

    public class MembershipRepository : IMembershipRepository
    {
        private readonly WebStoreDataContext _dataContext;
    
        public MembershipRepository(WebStoreDataContext dataContext)
        {
            _dataContext = dataContext;
        }
    
        public IEnumerable<User> GetUsers()
        {
            return _dataContext.Users;
        }
    
        public Guid GetUserId(string name)
        {
            return _dataContext.Users.Where(u => u.UserName == name).Select(u => u.UserId).Single();
        }
    }
    

    everything works, and I doesn’t need to use web request)

    So, you can create new instance of MembershipRepository or instance of YourAppNameDataContext (and workd directly with data context)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a ASP.NET Mvc app. I have a Data model say User
I am coding an ASP.NET MVC 3 app. When a user logs in I
I need to create a custom membership user and provider for an ASP.NET mvc
I am working with ASP.NET MVC. I need local time depending on user IP
I have a JInternalFrame and I need to get some Information from user (a
I need to get data from xml file <?xml version=1.0?> <xml> <User> <Agent> <id>cr4523</id>
Hi i'm making an app which need to get user's gmail account contact list
I have built an ASP.NET MVC app some time ago, and after a few
I have an ASP.NET MVC application which uses Entity Framework to get data. I
I still don't get the primary purpose of Html.Action in asp.net mvc. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.