VNS.Web
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package VNS.Web --version 1.0.0
NuGet\Install-Package VNS.Web -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VNS.Web" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VNS.Web --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: VNS.Web, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install VNS.Web as a Cake Addin #addin nuget:?package=VNS.Web&version=1.0.0 // Install VNS.Web as a Cake Tool #tool nuget:?package=VNS.Web&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
VNS Web
Some diffrent helper tools for Web applications
Installation
Use the package manager nuget to install.
dotnet add package VNS.Web
Intro
First things first, with this package, we are using httpcontext. You'll have to add the following to your program.cs
builder.Services.AddHttpContextAccessor();
Init
Add this to the top of you template
// Using
@using VNS.Web;
Util (Utility)
This contains a lot of diffrent small static methods to help you create simple code
// Get httpcontext
HttpContext Util.ctx;
// Get appsettings (Will load from appsettings.json)
IConfigurationRoot Util.AppSettings;
// Get remote IP (With cloudflare support - Using CF-Connecting-IP header if behind CF)
string Util.RemoteIP;
// Get status code
int Util.StatusCode;
// Get request method
string Util.ReqMethod;
// Is request method post
bool Util.IsPost;
// Get current url
string Util.GetCurrentUrl(bool includePath = true, bool includeQueryString = false);
// Request from form/querystring
string Util.Req(string key);
// Request from form
string Util.ReqForm(string key);
// Request from querystring
string Util.ReqQuery(string key);
// IPGeo (If no IP is set, RemoteIP will be used)
string Util.IPGeo(string ip = "");
// Domain whois (Currently only .com domains)
string Util.Whois(string domain);
// Request headers
IHeaderDictionary Util.ReqHeaders;
// Request header
StringValues Util.ReqHeader(string key);
// Request header
string Util.ReqHead(string key, bool htmlDecode = false);
// Request referer
string Util.ReqRef;
// Request host
string Util.ReqHost;
// Request user-agent
string Util.ReqUserAgent;
// Is host in ref
bool Util.IsHostInRef;
// Url Encode/Decode
string Util.UrlEncode(string value);
string Util.UrlDecode(string value);
// Html Encode/Decode
string Util.HtmlEncode(string value);
string Util.HtmlDecode(string value);
// Write to body
void Util.Write(object message);
// Redirect
void Util.Redirect(string url);
// Set content type - Default is set to: application/json
void Util.SetContentType(string contentType);
// Check if dynamic object contains a key
bool Util.ContainsKey(dynamic obj, string key);
// Session
void Util.SetSession(string key, object value);
T Util.GetSession<T>(string key);
void Util.RemoveSession(string key);
void Util.ClearSession();
// Cookie
void Util.SetCookie(string key, object value, DateTime? expires = null)
T Util.GetCookie<T>(string key);
void Util.DeleteCookie(string key);
// Render view as string
string Util.RenderViewAsString(Microsoft.AspNetCore.Html.IHtmlContent partial, System.Text.Encodings.Web.HtmlEncoder encoder);
// Get request files
IFormCollection Util.ReqFiles
// Get request file
IFormFile Util.ReqFile(string name);
// Save file
bool Util.SaveFile(IFormFile file, string path);
// Convert file to base64
string Util.ConvertToBase64(this IFormFile file);
// Posted body
System.IO.Stream Util.ReqBody();
string Util.ReqBodyAsString();
// Convert to XDocument
XDocument Util.Json2Xml(string json, string root = "");
XDocument Util.Obj2Xml(object obj, string root = "");
// Convert to JSON
string Util.Obj2Json(object obj);
string Util.Xml2Json(string xml);
// Convert to dynamic
T Util.Xml2Dynamic<T>(string xml);
T Util.Json2Dynamic<T>(string json);
T Util.Obj2Dynamic<T>(object obj);
// Convert stream
string Util.StreamToString(System.IO.Stream stream);
// This will just prettify json with indents for better display on web
string Util.FormatJson(Newtonsoft.Json.Linq.JObject json, bool fix4Web = false);
string Util.FormatJson(string json, bool fix4Web = false);
// Combine objects
object Util.CombineObj(object obj1, object obj2, object obj3 = null, object obj4 = null);
// Convert UnixTime to datetime
DateTime Util.DateFromUnixTime(long unixdate);
// Expose object
void Util.DrillObject(object obj);
// Clone object
T Util.CloneObj<T>(T obj);
// Clean HTML
string Util.CleanHtml(string html);
Secy (Security)
This contains a lot of diffrent small static methods to help you create simple code
// Generate random password
string Secy.GeneratePassword(int passwordLength = 10);
// Hash
string Secy.Hash(string text, bool Use256 = false, bool Use512 = false);
// A2B
string Secy.A2B(string input);
// B2A
string Secy.B2A(string input);
// Encrypt Text
string Secy.EncryptText(string text, string secret = "");
// Decrypt Text
string Secy.DecryptText(string text, string secret = "");
// Generate JWT token
string Secy.GetToken(object payload, string serectKey = "", int expireAfterMinutes = 1440, int notValidBeforeMinutes = 0);
// Check if JWT token is valid
bool Secy.IsTokenValid(string token, string serectKey, out string message);
// Get token headers from JWT
dynamic Secy.GetTokenHeaders(string token);
// Get token payload from JWT
dynamic Secy.GetTokenPayload(string token);
Soap
// Init
var soap = new SOAP(string url, string xmlns = "")
// Get / Set properties
Dictionary<string, string> soap.Headers;
// Execute
string soap.Execute(string method, string payloadXml = "");
// Result status
int soap.StatusCode;
string soap.StatusDescription;
bool soap.IsSuccess;
Rest
// Init
var rest = REST(string token);
or
var rest = new REST(string login = "", string password = "", string seperator = ":", string prefix = "Basic");
// Get / Set properties
string rest.ContentType;
string rest.Accept;
string rest.Method;
string rest.BaseUrl;
bool rest.KeepAlive;
Dictionary<string, string> rest.Headers;
// Execute
string rest.Execute(string url, string payload = "");
// Result status
int rest.StatusCode;
string rest.StatusDescription;
bool rest.IsSuccess;
SQL
// OBS: Add Nuget: System.Data.SqlClient
// Init
var sql = new SQL(string connectionString);
or
var sql = new SQL(string server, string database, string login, string password);
// Select data from SQL
var reader = sql.GetReader(string sql);
// Loop reader
while(reader.Read()){
// Do stuff
}
// Close reader
reader.Close();
// Insert, Update, Delete etc.
void sql.Execute(string sql);
// Close sql
sql.Close();
SQLite
// OBS: Add Nuget: Microsoft.Data.Sqlite
// Init
var sqlite = new SQLite(string connectionString);
or
var sqlite = new SQLite(string dataSource, bool foreignKeys, bool pooling);
// Select data from SQL
var reader = sqlite.GetReader(string sql);
// Loop reader
while(reader.Read()){
// Do stuff
}
// Close reader
reader.Close();
// Insert, Update, Delete etc.
void sqlite.Execute(string sql);
// Close sql
sqlite.Close();
Cookiebot
// Init
var cookiebot = new Cookiebot(string cookieName = "CookieConsent", string preferencesName = "preferences", string statisticsName = "statistics", string marketingName = "marketing");
// Properties
bool cookiebot.Necessary;
bool cookiebot.Statistics;
bool cookiebot.Marketing;
bool cookiebot.Preferences;
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- jose-jwt (>= 5.0.0)
- Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (>= 8.0.10)
- Microsoft.Data.Sqlite (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.3)
- System.Data.SqlClient (>= 4.8.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.