问题
I'm writing a simple utility console app to add new users, etc, to an SQL Server Membership Store.
The issue I'm running into is that I can't seem to add a reference to System.Web, so I can't access the Membership stuff. How does one go about doing this?
NOTE: I've found a few questions on stackoverflow that seem similar, but the answers revolved around MVC, and after attempting the suggested answers, the problem still remains.
Edit: Oded helped lead me to the answer. By default it was filtering by the "client profile", which doesn't have System.Web available. I had to retarget to .Net 4 instead of .Net 4 client profile as described in the following MSDN article.
http://msdn.microsoft.com/en-us/library/bb398202.aspx
回答1:
Make sure you are targeting the full framework in your project (right click on the project node and select Properties
) - In the Application
tab there is a drop down for Target Framework
.
Make sure this does not use a client profile.
回答2:
What exactly prevents to you to add reference to System.Web in a console application? Just add appropriate reference via references management in VS. After that you should configure your application with App.config and work with Membership services as in web applcation
来源:https://stackoverflow.com/questions/9398194/accessing-asp-net-membership-in-a-console-application