Git Product home page Git Product logo

westwind.aspnetcore's Introduction

Westwind.AspNetCore

Utility library providing useful helpers, formatters and extensions for ASP.NET Core

NuGet Pre Release

This is a small helper package that provides a number of small helper and extension classes that facilitate common operations in ASP.NET Core and MVC applications.

Installation

You can install the package from NuGet in Visual Studio:

Westwind.AspnetCore Package

PM> install-package westwind.aspnetcore

or the dotnet command line:

dotnet add package westwind.aspnetcore

Features

MVC Functionality

  • BaseController and BaseViewModel implementation
    A common base controller class that adds support for an auto-initialized BaseViewModel from which other VMs can inherit. Allows for automatic initialization of common features like ErrorDisplay and Base View models. Also optionally sets up a UserState object that can be used to persist user data (display name, stats, etc) across requests.

  • ViewRenderer
    Render Razor/MVC view output to a string using a controller context.

  • FormVariable to Object Instance Binder
    Request.Form unbind routine that allows you to unbind form variables into an existing object only updating properties that are are available in the request form context.

  • AppUser ClaimsPrincipal and Cookie Authentication Helper
    A AppUser class that wraps a ClaimsPrincipal and makes it easier to add and retrieve claims as well as easily login and logout all from a single helper object.

  • Bootstrap Alert ErrorDisplay Tag Helper and Controller Support Feature
    In most MVC applications you need some sort of error display and this ErrorDisplay TagHelper makes it quick easy to display an Alert box from a custom ErrorDisplayModel input. Helper methods like ShowError() or ShowInfo() on BaseViewModel make it very easy to display error and informational messages on pages.

Api Functionality

  • Api Error Handling Filter
    A custom API error filter implementation that returns API responses on exceptions. Also provides a standardized ApiExecption class that can be used to force responses with specific HTTP response codes.

  • Api Base Response Object
    ApiResponse base class that can be used to return consistent API results that include error status, error message, status code as well as the actual data. Both typed and untyped versions.

  • RawRequest Body String Formatter
    API formatter that allows for receiving raw non-json content to string and byte[] parameters, which otherwise isn't supported by MVC's API implementation. More info in blog post.

  • User Token Manager
    A database driven token manager that can create, store, validate and manage the life time of short lived generated tokens. Useful for creating tokens that are assigned after an initial authentication and then used for API access and can be easily validated.

  • JWT Helper
    Helper class that makes it easier to create and retrieve JWT tokens.

General ASP.NET Core

  • Custom Headers Middleware
    Allows adding and removing of HTTP headers to every request using middleware configuration.

  • HttpRequest Extensions

    • GetBodyStringAsync() and GetRawBodyBytesAsync() - retrieve raw non-JSON content
    • GetUrl() - Returns the Absolute URL for the current request.
    • Params() - Return an item from Form, Query or Session collections.
    • IsFormVar() - Determines if a Form variable exists
    • IsPostback() - Determines if request is a Post/Put operation
    • IsLocal - Determines if the current URL is a local machine URL
  • HttpContext Extensions

    • MapPath() - Map virtual path to physical path on disk
  • DataProtector Wrapper
    Helper to make it easier to use the DataProtector API to create secure tokens.

  • UserState Helper
    The UserState object greatly simplifies working with auth 'cached' user data that can be stored across requests. Useful for caching things like username, main IDs to reduce data base lookups or simply to carry global values across requests. Data is stored either in an Identity Claim or a custom encrypted cookie. The class supports easily serialization and auto-loading and saving. Can be extended by subclassing and adding your own custom properties to track beyond several common ones.

License

The Westwind.Web.MarkdownControl library is an open source product licensed under:

All source code is ยฉ West Wind Technologies, regardless of changes made to them. Any source code modifications must leave the original copyright code headers intact if present.

There's no charge to use, integrate or modify the code for this project. You are free to use it in personal, commercial, government and any other type of application and you are free to modify the code for use in your own projects.

Give back

If you find this library useful, consider making a small donation using the Sponsor link.

westwind.aspnetcore's People

Contributors

rickstrahl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

westwind.aspnetcore's Issues

WebUtils.SetUserLocale

Hi there,
Does the WebUtils.SetUserLocale function work with the Asp.Net Core version?
It works perfectly if I change my browser language, or if I add the culture= in the query string, but not if I specify the culture and UI culture (these are both strings). I'm trying to persist this using a simply cookie.

WebUtils.SetUserLocale(culture, culture, null, true, null, HttpContext);

Thanks,
David

Cross site scripting vulnerability

It appears the markdown component is exposing cross site scripting vulnerabilities.

When the following text is placed inside the tag, the text is being rendered as script.
Recycleablequp97<ScRiPt>alert(1)</ScRiPt>qgxsv

When the markdown tag is not used, it is rendered as text by .net:
Recycleablequp97&lt;ScRiPt&gt;alert(1)&lt;/ScRiPt&gt;qgxsv

I have read the closed issue on this, but I feel like the markdown component should not be undoing the default behavior for rendering script tags.

I'm using .net core 2.1.2

Markdown now requires trailing slash for subsite

I have a subsite under my domain and now when I try to navigate to its landing page I get this error:

An unhandled exception has occurred while executing the request. System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex at System.String.Substring(Int32 startIndex, Int32 length) at Westwind.AspNetCore.Markdown.MarkdownPageProcessorMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.HttpsPolicy.HstsMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

If I add a trailing slash then the page works correctly.

https://myweb.com/subsite - doesn't work
https://myweb.com/subsite/ - this works (hits the home controller and displays the index page)

Any clues?

Thanks.

Change target framework to netstandard2.0

Would be great if this was dependent upon netstandard2.0 rather than netcoreapp2.0, some of us are still using full framework for web apps.

I'd be happy to submit a pull request for this... I note that the latest version of this repo currently has a compilation issue however.

Add licence

Please, add some licence.

I dont know what can i do with your helpers (and i reaaaaly want to dig in your MarkdawnTagHelper ๐Ÿ˜ )

Change markdown renderer used

For a project I need to be able to generate AMP as well as "normal" HTML pages. I'm using your library at the moment, works great thanks!

I was wondering if there is any way to change the renderer used by Markdown.ParseHtmlString to a custom one so that I can generate AMP-specific html?

Issue with XSS

Hi, we're using your library over at csharpfritz/CoreWiki#144 to render wiki content and comments, but we appear to be having an issue with XSS.

Is this something that can be fixed in the library, or something we have to update on our end when using the <markdown> tag?

How we're using the library:

https://github.com/csharpfritz/CoreWiki/blob/dev/CoreWiki/Pages/Components/ListComments/ListComments.cshtml#L41

https://github.com/csharpfritz/CoreWiki/blob/dev/CoreWiki/Pages/Details.cshtml#L19

Comment log of issue:

csharpfritz/CoreWiki#144

Custom Middleware add/remove headers

I was looking into ways of adding and removing headers from my ASP.NET Core application. It's an API so there is no UI to it. After looking around I worked out that using the middleware technique to add and remove headers is probably the best as I need to include information in every response. I used the techniques in the CustomMiddleware.cs class and added code to the Startup.Configure method. Adding headers seems to work so for example:

opt.HeadersToAdd.Add("X-API-Version", sVersionString);
opt.HeadersToAdd.Add("X-ClientCommand", sCommandToExecute);

However, removing doesn't remove the headers. Any thoughts? It's not overly important to remove these, but I like to remove somethings just to make the response cleaner.

opt.HeadersToRemove.Add("X-Powered-By");
opt.HeadersToRemove.Add("x-aspnet-version");
opt.HeadersToRemove.Add("Server");

Missing trailing slash causes out of index exception

I have a subsite under my domain and now when I try to navigate to its landing page I get this error:

An unhandled exception has occurred while executing the request. System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex at System.String.Substring(Int32 startIndex, Int32 length) at Westwind.AspNetCore.Markdown.MarkdownPageProcessorMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.HttpsPolicy.HstsMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

If I add a trailing slash then the page works correctly.

https://myweb.com/subsite - doesn't work
https://myweb.com/subsite/ - this works (hits the home controller and displays the index page)

Any clues?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.