1

I have a build in VB.NET as ASP.NET (.NET Framework) so it's not a CORE application.

The web site has lot's of API's build in WebApi 2 inside it and now I was going to make an authentication API via JWT, actually I have yet a Controller which return JWT token but now I have to validate it...

As I've read on the web I have to validate it throw a middleware like OWIN so I need to add the following method inside Startup class:

Public Class Startup
    Public Sub Configuration(ByVal app As IAppBuilder)
        app.UseJwtBearerAuthentication(New JwtBearerAuthenticationOptions With {
            .AuthenticationMode = AuthenticationMode.Active,
            .TokenValidationParameters = New TokenValidationParameters() With {
                .ValidateIssuer = True,
                .ValidateAudience = True,
                .ValidateIssuerSigningKey = True,
                .ValidIssuer = "url",
                .ValidAudience = "url",
                .IssuerSigningKey = New SymmetricSecurityKey(Encoding.UTF8.GetBytes("my_secret_key_12345"))
            }
        })
    End Sub
End Class

But the issue is that by right-clicking the project and by > adding new element the Startup class doesn't exist...

So how can I create one? As I've read the project must be .NET Core to use Owin Startup class.. so should I rebuild all my project in Core or I can anyway find a way to authenticate JWT token without it?

3

1 Answer 1

1

You can add an Owin startup class to a .NET Framework project by using the following attribute

[assembly: OwinStartup(typeof(myNamespace.Startup))]

namespace myNamespace
{
    /// <summary>
    /// OWIN startup class, automatically starts when app starts
    /// </summary>
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)

This should work in vb .net by using this syntax

<Assembly: OwinStartup(GetType(myNamespace.Startup))]

Just add a regular class called Startup to your project and this should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.