Hi
Is there any Sample Code for Blog available which can be integrated with my Web Application
Thanks
Hi
Is there any Sample Code for Blog available which can be integrated with my Web Application
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal YelveRank #178 · 13.6K reputationPosted Apr 21, 2023, 6:15 AM EDT
Hi Ramco,
If you want to create personal blog in asp.net do refer below links
https://www.c-sharpcorner.com/UploadFile/201fc1/creating-a-customizable-personal-blog-in-Asp-Net/
https://hackernoon.com/coding-a-blog-with-c-tk9p32po
Ramco RamcoRank #462 · 5.4K reputationPosted Apr 21, 2023, 6:23 AM EDT
Hi Vishal
I need in c# Asp.net. Secondly is there any other Free Blogging Software which can be easily integrated.
Thanks
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 21, 2023, 9:56 PM EDT
To integrate WordPress into your ASP.NET web application, you can use the WordPress REST API, which provides a set of endpoints for accessing WordPress content and functionality. Here's a sample code to get you started:
First, you need to install the WordPressSharp NuGet package:
Then, you can use the WordPressClient class to access the WordPress REST API. Here's an example code that retrieves a list of posts:
using WordPressSharp; using WordPressSharp.Models; // Create a new WordPress client var client = new WordPressClient("http://your-wordpress-site.com/wp-json/wp/v2"); // Retrieve a list of posts var posts = await client.ListPosts(); // Loop through the posts and display their titles foreach (var post in posts) { Console.WriteLine(post.Title.Rendered); }I created a new WordPress client by passing the base URL of the REST API endpoint to the constructor. We then called the ListPosts() method to retrieve a list of posts, and looped through the posts to display their titles. You will need to authenticate with WordPress in order to access protected endpoints, such as creating or editing posts. You can do this by passing a username and password to the WordPressClient constructor, or by using OAuth authentication.
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 21, 2023, 10:02 PM EDT
Part 1
Integrating Medium blogging platform into an ASP.NET web application involves using the Medium API to authenticate the user and retrieve the necessary data from Medium. Here is some sample code to get started:
1. First, you'll need to create a Medium Integration on the Medium Developers page. This will give you a Client ID and Client Secret that you'll need later.
2. Install the NuGet package `Microsoft.AspNet.WebApi.Client` in your ASP.NET web application.
3. Create a new `ApiController` with an action that will handle the authentication flow. This action will redirect the user to Medium's authentication page, where they will grant permission for your application to access their Medium account. After the user has granted permission, they will be redirected back to your application's callback URL with an authorization code.
public class MediumController : ApiController { private const string ClientId = ""; private const string ClientSecret = ""; private const string CallbackUrl = ""; [HttpGet] public IHttpActionResult Authorize() { var authorizeUrl = $"https://medium.com/m/oauth/authorize?client_id={ClientId}&scope=basicProfile,publishPost&state=random-state&response_type=code&redirect_uri={CallbackUrl}"; return Redirect(authorizeUrl); } [HttpGet] public async Task Callback(string code, string state) { // Exchange authorization code for access token using (var client = new HttpClient()) { var request = new HttpRequestMessage(HttpMethod.Post, "https://api.medium.com/v1/tokens") { Content = new FormUrlEncodedContent(new[] { new KeyValuePair("code", code), new KeyValuePair("client_id", ClientId), new KeyValuePair("client_secret", ClientSecret), new KeyValuePair("grant_type", "authorization_code"), new KeyValuePair("redirect_uri", CallbackUrl) }) }; var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsAsync(); // Store the access token for later use // Redirect the user to your application's main page return Redirect(""); } else { return BadRequest("Unable to obtain access token from Medium."); } } } } public class AccessTokenResponse { public string AccessToken { get; set; } public string RefreshToken { get; set; } public int ExpiresAt { get; set; } }Tuhin PaulRank #7 · 71.9K reputationPosted Apr 21, 2023, 10:04 PM EDT
Part 2
4. Once the user has authorized your application, you can use the access token to make requests to the Medium API. Here's an example of retrieving the user's profile information:
using System; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { string accessToken = "your_access_token_here"; using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://api.medium.com"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage response = await client.GetAsync("/v1/me"); if (response.IsSuccessStatusCode) { string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } else { Console.WriteLine("Error: " + response.StatusCode); } } } }In this example, we use the HttpClient class to make a GET request to the Medium API's /v1/me endpoint, which returns the user's profile information. We set the Authorization header of the request to include the user's access token, which we obtained in step 3. If the request is successful, we print the response body to the console. Otherwise, we print the error status code.