Where is the IConfiguration.Get method in ASP.NET 6 (vnext) after update to beta6? - asp.net

For the moment almost all blog posts covering configuration with the new ASP.NET 5 and MVC 6 using json for config is using something like this:
var token = configuration.Get<string>("AppData:CompanyName");
For example this question: How to read AppSettings values from Config.json in ASP.NET Core
But since 6 august this function is removed (if you're using bleeding edge releases) with almost no information on what to use instead.
For me this first occurred when switching to from beta5 to beta6 of Microsoft.Framework.Configuration.Json.

tl;dr;
Do it like this to get it working:
var companyName = Configuration["AppData:CompanyName"];
var branchName = Configuration["AppData:BranchName"];
// etc.
Explanation and source:
This commit removed the Get function:
https://github.com/aspnet/Configuration/commit/ddd7c42ece30f0b7bb57a91ae7a627f2f99b9cf2
Some further comments when digging in the issue can be found here:
https://github.com/aspnet/Configuration/issues/246

Related

Swagger issue: Only one .json file is generator for the default version

I just have tested a great article about WebApi versioning from this website:
https://www.meziantou.net/versioning-an-asp-net-core-api.htm
It works partially: It should generate two Swagger documents, one for each version.
But it actually only generates a document for the given defaultApiVersion. In my example this was set to 2.0. The older WebApi controllers marked with 1.0 do not result into a document. And based on the 2 commands below, I had also expected that the WebApi controllers without any version attribute should be visible in the 2.0 documentation. (Which doesn't happen either).
options.DefaultApiVersion = new ApiVersion(2, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
Can someone give a suggestion about what is happening here?
Kind regards, Mark.

How to get a Solution name in .Net Core Project

How can I get the Solution name in .Net Core project.
I have searched a lot on web but could not find anything
So how can I get the "Clean_Architecture" as a solution name.
Thanks in advance.
You need to set breackpoints to check the following code and find which is your solution name.
Try this:
var SolutionFullPath = Directory.GetParent(Directory.GetCurrentDirectory()).FullName;
var tempStrings = SolutionFullPath.Split('\\');
var solutionName = tempStrings[tempStrings.Length - 1];;
Solution is simply a container for projects and haven't got any special meaning in program context. But you can try following to get the folder of project that maybe the same as solution name:
var solutionName = Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);

Breeze and the EdmBuilder for OData v4

I was able to create an OData (v3) service with WebApiOdata and EntityFramework at server side and Breeze at client side thanks to this document.
Now I'd like to do the same with the version 4 of OData spec. but there is a problem. The EdmBuilder class provided by Breeze depends on the 'Microsoft.Data.Edm' which is related to the version 3.
In the EdmBuilder these 2 lines prevent the project from building:
using Microsoft.Data.Edm.Csdl;
using Microsoft.Data.Edm.Validation;
which is normal, because my project has a reference to 'Microsoft.OData.Edm'(for v4) instead of 'Microsoft.Data.Edm'(for v3).
So I replaced the 2 using statements, by this:
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;
Now the project can build, but at runtime it throws this exception
"Encountered the following errors when parsing the EDMX document:
UnexpectedXmlElement : The element 'Edmx' was unexpected for the root
element. The root element should be Edmx. : (1, 40)"
from the EdmBuilder class at this point:
using (var reader = XmlReader.Create(stream))
{
return EdmxReader.Parse(reader);
}
Is there any way to solve this problem ??? like a new EdmBuilder class that I can download somewhere?
P.S.: I'm using code first migration and this code to configure OData route in the 'WebApiConfig' :
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "OData",
model: EdmBuilder.GetEdm<MyDbContext>(),
batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
We are currently working on a breeze release that works with OData v 4.0. I will post back here when it is released, which should be in the fairly near future.

Facebookclient example in .net 3.5 [duplicate]

I've been asked to develop a facebook application that allows users of their current system to find each other using a this facebook app. Unfortuantely their requirements are that it has to be build in ASP.NET 3.5 (Easier for their clients distribution purposes).
I am a experienced PHP developer although I have in the past used C# for windows applications. I have found a facebook api that looks suitable - http://facebooksdk.codeplex.com/. The problem I am having is that all availble examples use .NET 4.
I must admit I'm struggling to get to grips with the api and I know from the past I learn best through example. Could anyone provide a link to examples or some basic code I experiment with?
I would really appreciate any advice or input you have on the situation.
Thanks, Jason.
Update
Using the answer below and the following resource (http://osnapz.wordpress.com/2010/04/23/using-asp-net-with-facebooks-graph-api-and-oauth-2-0-authentication/) it is easy enough to make start on facebook application.
One issue I also had was the server (1&1) I was using needed proxy setting added to the web.config
Example:
<system.net>
<defaultProxy>
<proxy
usesystemdefault = "false"
bypassonlocal="false"
proxyaddress="http://ntproxyus.lxa.perfora.net:3128"
/>
</defaultProxy>
</system.net>
Until you become more familiar with ASP.NET, I would suggest integrating with the FacebookClient() rather than the more involved
the one thing you will have to understand is the difference between dynamic and using IDictionary. For C# 4.0 and up you can use dynamic, but for 3.5 you must use the old IDictionary.
Here's a good example of how to convert from dynamic to IDictionary (so you can use the 4.0 examples as a guide)
var fb = new FacebookClient("{access_token}");
dynamic result = fb.Get("/me");
var name = result.name;
Response.Write("Hi " + name);
Converts to:
var fb = new FacebookClient("{access_token}");
var result = (IDictionary<string, object>)fb.Get("/me");
var name = (string)result["name"];
Response.Write("Hi " + name);
I hope that gets you on your way as far as converting the examples.

how to get the first tweet from my twitter and display it on my webpage?

Please can somebody help to get the first tweet from my twitter and display it on my website.
I am using asp.net 2.0.
Thanks
There are many ways to do this depending on your requirements. Personally, I have accomplished this using the Twitterizer library.
var feed = TwitterTimeline.UserTimeline(new UserTimelineOptions() {
CacheOutput = true,
CacheTimespan = TimeSpan.FromMinutes(1),
ScreenName = "twitter_username",
Count = 1
});
var firstPost = feed.FirstOrDefault();
The advantage of this approach is that you are not required to have a Twitter API key in order to pull the data. It doesn't get much simpler than this!
Update
After you clarified .NET 2.0 I found this .NET 2.0 Twitter API wrapper. Haven't used it myself, but it may be worth a look. Yedda Twitter C# Library
If that that library/wrapper won't do, JSON.NET also has a .NET 2.0 compatible binary.
Just a caveat, JSON.NET would be the most involved simply because the various wrappers that exist will be specialized to Twitter, whereas JSON.NET is just a general JSON parser (Twitterizer even uses it).
In my own opinion, possibly the easiest solution of all is to use jQuery to pull up the API for you. Obviously, that would be done as a client event so it would not be as "ideal" as the alternative. Still it's a the most "no-fuss" solution. Here's a blog post on calling the Twitter API with jQuery.
Take a look at TweetSharp (works on .NET 2.0)
This example doesn't show your tweet, but you get the idea of how easy it is.
using TweetSharp;
TwitterService service = new TwitterService();
IEnumerable<TwitterStatus> tweets = service.ListTweetsOnPublicTimeline();
foreach (var tweet in tweets)
{
Console.WriteLine("{0} says '{1}'", tweet.User.ScreenName, tweet.Text);
}

Resources