1648768740
Swagger UIは、Restfulサービス用の非常に強力なドキュメントツールです。これは、RESTfulAPIを記述および使用するためのフレームワークです。これにより、メソッド、パラメーター、およびモデルの文書化システムがサーバーコードに緊密に統合されます。Swashbuckleを任意のWebAPIプロジェクトに追加して、生成された仕様をUI(swagger-ui)とともに簡単にカスタマイズできます。Swagger UIは、Swashbuckleを使用してドキュメントを表示します。スワッシュバックルには、ルックアンドフィールをカスタマイズするために使用できる拡張ポイントがいくつかあります。
この記事では、SwaggerUIをカスタマイズする手順を示します。
この記事を読む前に、以下に説明するように私の以前の記事にアクセスしてください。
Swashbuckleでカスタマイズできるものを以下に示します。
従うべきステップ、
App_Startフォルダーの下にあるSwaggerConfig.csファイルを開くと、Swaggerに関連するすべての構成が存在することがわかります。Swagger Uiには、GET()やGET(ID)などのメソッドからXMLコメントを読み取るための機能がいくつかあります。
ステップ1
以下に示すように、EmployeeController.csおよびGET()メソッドのXMLコメントに移動します。そのためには、3つのスラッシュ(または単にスラッシュ)///と入力するだけで、XMLセクションが自動的に作成され、[概要]セクションと[パラメーター]セクションに独自のコメントが書き込まれます。
GET()メソッドの場合
GET(ID)メソッドの場合
ステップ2
もう1つの設定が必要です。そのためには、プロジェクトを右クリックしてプロパティに移動します。次のステップは、[ビルド]を選択してXMLドキュメントファイルを選択し、それらの変更を保存することです。
ステップ3
App_Startフォルダーの下のSwaggerConfig.csファイルに移動し、次のコードを追加します。
private static string GetXmlCommentsPath() {
return String.Format(@ "{0}\bin\WebAPIProj.XML", System.AppDomain.CurrentDomain.BaseDirectory);
}
C#
ここで、WebAPIProj.XMLはWebAPIプロジェクトの名前です。だから、あなた自身のプロジェクト名を入れてください。
ステップ4
SwaggerConfig.csファイルの以下のコード行のコメントを解除します。
c.IncludeXmlComments(GetXmlCommentsPath());
C#
これらの変更がSwaggerConfig.csファイルで行われた後、ソリューションを構築して実行します。
出力
ここでは、GET()メソッドのXMLコメントを以下に示します。
また、EmployeeControllerのGET(ID)メソッドのparamセクションに説明が追加されているので、従業員IDを確認できます。
ステップ5
ここでは、スタイルシートを使用してSwaggerUIをカスタマイズすることもできます。Contentフォルダーの下にSwaggerStyle.cssという名前のスタイルシートファイルを1つ追加しました。
以下に示すように、SwaggerStyle.cssファイルを右クリックし、ビルドアクションの[埋め込みリソース]オプションを選択します。
ここでは、以下に示すように、SwaggerStyle.cssファイルにCSSクラスを追加しました。
.swagger-section #header {
background-color: #ffd800;
padding: 14px;
}
CSS
このクラスには、背景色とヘッダーへのパディングの2つのプロパティがあります。
ステップ6
次に、このSwaggerStyle.cssファイル参照をSwaggerConfig.csファイルに追加します。以下のコード行のコメントを解除します。
このコード行を次のように変更します。
c.InjectStylesheet(thisAssembly, "WebAPIProj.Content.SwaggerStyle.css");
C#
ここでは、WebAPIProj / Content/SwaggerStyle.cssの下にあるCSSファイルのフルネームについて説明しました。
出力
ここでは、ヘッダーの背景色が変更され、パディングプロパティも変更されていることがわかります。
このように、必要に応じてSwaggerUI全体をカスタマイズできます。
ここでは、Contentフォルダーの下にSwaggerScript.jsという名前のJavaScriptファイルを追加しました。
以下に示すように、SwaggerScript.jsファイルを右クリックし、ビルドアクションの[埋め込みリソース]オプションを選択します。
ここでは、以下に示すように、SwaggerScript.jsファイルにjavascriptコードを追加しました。
$(document).ready(function () {
alert("Swagger Script Alert Added.");
});
JavaScript
ステップ7
次に、このSwaggerScript.jsファイル参照をSwaggerConfig.csファイルに追加します。以下のコード行のコメントを解除します。
このコード行を次のように変更します。
c.InjectJavaScript(thisAssembly, "WebAPIProj.Content.SwaggerScript.js");
C#
ここでは、WebAPIProj / Content/SwaggerScript.jsの下にあるJSファイルのフルネームについて説明しました。
出力
ここでは、以下に示すように、SwaggerUIがロードされたときのjavascriptアラートメッセージを確認できます。
この記事では、以下の詳細を学びました。
ありがとう&もっとお楽しみに
ソース:https ://www.c-sharpcorner.com/article/customize-swagger-ui-in-asp-net-web-api-restful-service/
#aspdotnet #restful #xml #swagger #ui
1602560783
In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.
To demonstrate CRUD operations – insert, update, delete and retrieve, the project will be dealing with details of a normal bank transaction. GitHub repository for this demo project : https://bit.ly/33KTJAu.
Sub-topics discussed :
In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N).
From new project window, Select Asp.Net Core Web Application_._
Once you provide the project name and location. Select Web Application(Model-View-Controller) and uncheck HTTPS Configuration. Above steps will create a brand new ASP.NET Core MVC project.
Let’s create a database for this application using Entity Framework Core. For that we’ve to install corresponding NuGet Packages. Right click on project from solution explorer, select Manage NuGet Packages_,_ From browse tab, install following 3 packages.
Now let’s define DB model class file – /Models/TransactionModel.cs.
public class TransactionModel
{
[Key]
public int TransactionId { get; set; }
[Column(TypeName ="nvarchar(12)")]
[DisplayName("Account Number")]
[Required(ErrorMessage ="This Field is required.")]
[MaxLength(12,ErrorMessage ="Maximum 12 characters only")]
public string AccountNumber { get; set; }
[Column(TypeName ="nvarchar(100)")]
[DisplayName("Beneficiary Name")]
[Required(ErrorMessage = "This Field is required.")]
public string BeneficiaryName { get; set; }
[Column(TypeName ="nvarchar(100)")]
[DisplayName("Bank Name")]
[Required(ErrorMessage = "This Field is required.")]
public string BankName { get; set; }
[Column(TypeName ="nvarchar(11)")]
[DisplayName("SWIFT Code")]
[Required(ErrorMessage = "This Field is required.")]
[MaxLength(11)]
public string SWIFTCode { get; set; }
[DisplayName("Amount")]
[Required(ErrorMessage = "This Field is required.")]
public int Amount { get; set; }
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime Date { get; set; }
}
C#Copy
Here we’ve defined model properties for the transaction with proper validation. Now let’s define DbContextclass for EF Core.
#asp.net core article #asp.net core #add loading spinner in asp.net core #asp.net core crud without reloading #asp.net core jquery ajax form #asp.net core modal dialog #asp.net core mvc crud using jquery ajax #asp.net core mvc with jquery and ajax #asp.net core popup window #bootstrap modal popup in asp.net core mvc. bootstrap modal popup in asp.net core #delete and viewall in asp.net core #jquery ajax - insert #jquery ajax form post #modal popup dialog in asp.net core #no direct access action method #update #validation in modal popup
1596104770
Looking to outsource your asp dot net development requirement?
ASP.Net is a special feature of the DOT Net framework created by Microsoft. At HourlyDeveloper.io, we have a team of experienced ASP.Net developers who are experts in delivering custom solutions based on your business requirements. Hire ASP.Net Developers who will provide tailored solutions to facilitate your business growth.
Consult with experts: https://bit.ly/3fNpVqr
#hire asp.net developers #asp.net development company #asp.net development services #asp.net development #asp.net developer #asp.net
1602564619
User registration and authentication are mandatory in any application when you have little concern about privacy. Hence all most all application development starts with an authentication module. In this article, we will discuss the quickest way to use **ASP.NET Core Identity for User Login and Registration **in a new or existing MVC application.
Sub-topics discussed :
ASP.NET Core Identity is an API, which provides both user interface(UI) and functions for user authentication, registration, authorization, etc. Modules/ APIs like this will really be helpful and fasten the development process. It comes with ASP.NET Core Framework and used in many applications before. Which makes the API more dependable and trustworthy.
ASP.NET Core MVC with user authentication can easily be accomplished using Identity.UI. While creating the MVC project, you just need to select Authentication as Individual User Accounts.
The rest will be handled by ASP.NET Core Identity UI. It already contains razor view pages and backend codes for an authentication system. But that’s not what we want in most of the cases. we want to customize ASP.NET Core Identity as per our requirement. That’s what we do here.
First of all, I will create a brand new ASP.NET Core MVC application without any authentication selected. We could add ASP.NET Core Identity later into the project.
In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N). From new project window, select ASP.NET Core Web Application.
Once you provide the project name and location. A new window will be opened as follows, Select _Web Application(Model-View-Controller), _uncheck _HTTPS Configuration _and DO NOT select any authentication method. Above steps will create a brand new ASP.NET Core MVC project.
#asp.net core article #asp.net core #add asp.net core identity to existing project #asp.net core identity in mvc #asp.net core mvc login and registration #login and logout in asp.net core
1622461866
A versatile Web & Mobile App Development framework technology that is fast, reliable, and easy to use is ASP.NET. ASP.NET gives the developer complete control over development and can be used on any project big or small.
Want to develop a website or mobile app with ASP.NET?
WebClues Infotech with years of experience and a highly skilled development team can be your go-to agency for your Web & Mobile App Development requirements. With an expert developer team of more than 150+ members, WebClues Infotech has successfully delivered more than 1500 projects worldwide.
Want to know more about the ASP.NET framework?
Visit: https://www.webcluesinfotech.com/asp-net-web-development/
Share your requirements https://www.webcluesinfotech.com/contact-us/
View Portfolio https://www.webcluesinfotech.com/portfolio/
#asp.net web development company #asp.net web development company usa #asp.net development company in india #asp.net development company #.net software development company #hire asp.net developer
1591862548
ASP.NET Core MVC has introduced quite a few concepts that new (or new-to-ASP.NET) web developers might have some difficulty getting caught up with. My ASP.NET Core Demystified series is designed to help these developers get started building their own custom, full-fledged, working AASP.NET Core applications. In
#asp.net core demystified #mvc - asp.net core #asp.net core #asp.net #programming