Getting an error message "IAppBuilder could not be found" - c#

I am doing user authentication using owin middleware. But for IppBuilder it is giving error "IAppBuilder could not found. Are you missing Reference?" I have already installed nuggets packages related to owin as shown while searching on google.
Any help would be appreciated. Here is my code:
using Microsoft.Owin;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using OpenConfigure.Core;
[assembly: OwinStartup(typeof(CURDApis.API.Startup))]
namespace CURDApis.API
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
app.UseWebApi(config);
}
}
}

Related

Not able to see the logs of a web application

I have created a web application, below is the entry point of that application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Routing;
using Microsoft.Graph.Communications.Common.Telemetry;
namespace ProductsApp3
{
public class WebApiApplication : System.Web.HttpApplication
{
private readonly IGraphLogger logger;
public WebApiApplication()
{
this.logger =
new
GraphLogger(typeof(WebApiApplication).Assembly.GetName().Name,
redirectToTrace: true);
}
protected void Application_Start()
{
this.logger.Info("WorkerRole has been started");
Console.WriteLine("Sai");
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
}
But Nowhere I can see the below statements when I run the application in Visual Studio
this.logger.Info("WorkerRole has been started");
Console.WriteLine("Sai");"
can someone help me please where I can see this log inormation locally and also in AKS if I deploy this app there?.

How can we add DI (Dependency Injection) of a class library to multiple projects in C# asp.net 6

here I am trying to add dependencies from SchoolAppASPv2.Infrastructure to SchoolAppASPv2.Identity but I am not being able to.
It shows an error in using SchoolAppASPv2.Infrastructure
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using SchoolAppASPv2.Identity;
using SchoolAppASPv2.Identity.Data;
using SchoolAppASPv2.Identity.Models;
using SchoolAppASPv2.Identity.Services;
using SchoolAppASPv2.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddInfrastructure(builder.Configuration);
builder.Services.AddControllers();
builder.Services.AddTransient<ILoginService<ApplicationUser>, EFLoginService>();
builder.Services.AddDbContext<ApplicationDbContext>(options => {
options.UseSqlServer(
builder.Configuration.GetConnectionString("SchoolAppAspConnection"),
b =>
b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName));
});
And This Being the Dependency Injection Class
The Dependency class has been used in 1 project but here I am trying to add it into another project. I am trying to connect the DbContext class of the SchoolAppASPv2.Infrastructure but I am being unable to add it
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SchoolAppASPv2.Application.Common.Interface;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SchoolAppASPv2.Infrastructure.DataBase;
using SchoolAppASPv2.Infrastructure.Services;
namespace SchoolAppASPv2.Infrastructure
{
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection
services, IConfiguration configuration)
{
var connectionString =
configuration.GetConnectionString("SchoolAppAspConnection");
}
}

Code compiles and runs in Visual Studio even though it has the name of a class that isn't referenced

I have an ASP.NET Core web application I'm testing, and it shouldn't be compiling or running, but it does both. The problem should be that I'm using a class name -- ActionResult -- from an assembly that isn't referenced. Notice how ActionResult is not blue like a resolved class name, and also notice how there is no compiler error underlined:
Furthermore the project compiles and runs just fine (although doesn't behave as expected, naturally, which is to respond with HTTP GET requests to that URL with the values seen above). What is going on?
Here's all the code just for reference:
Program.cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplication2
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
Startup.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace WebApplication2
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "api/{Default}");
});
}
}
}
DefaultController.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace WebApplication2.wwwroot
{
[Route("api/[controller]")]
[ApiController]
public class DefaultController : ControllerBase
{
// GET: api/Default
[HttpGet]
public async Task<ActionResult<IEnumerable<string>>> Get()
{
return Task.FromResult(new string[] { "value1", "value2" });
}
}
}
Here's VS and .NET info:
Microsoft Visual Studio Professional 2017
Version 15.9.4
VisualStudio.15.Release/15.9.4+28307.222
Microsoft .NET Core 2.1
ActionResult is in the Microsoft.AspNetCore.Mvc namespace which you are in fact referencing. Visual Studio just isn't highlighting correctly, which is a bug I encounter off and on.

In which module is the HttpContext.Session defined

I am in MVC Core application. I added System.Web to my using clause but still I cannot access httpcontext.Session. The intellisense does not give me any option for httpcontext. Thanks for your answer.
Edit:
I have found this answer: https://benjii.me/2016/07/using-sessions-and-httpcontext-in-aspnetcore-and-mvc-core/
But when I add the nuget package: Microsoft.AspNetCore.Session into my project the solution won't even load anymore. So I had to remove it
Edit: Now I have added the most recent version of the package from nuget console. But I still do not have HttpContext option in the intellisense so I cannot access the session. Please help..
In System.Web I have only the following object: HttpUtility and nothing more,
is there anyone that can help? Without Sessions I cannot write any applications. Should I reinstall Visual Studio?
Notice**: In my webforms application I have the object Session in system.web
As required I post my Startup.cs and the file in which I am trying to call the object Session:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Localization;
using WebCoreFly.Models;
namespace WebCoreFly
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<FlyDBContext>(options =>
options.UseSqlServer(Configuration["Data:WebCoreFly:ConnectionString"]));
services.AddSingleton<FlyRepository>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
the class in whic I am trying to call session:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
namespace WebCoreFly.Models.ViewModels
{
public class UserRepository1
{
public UserRepository1()
{
System.Web.HttpContext //does not recognize it
}
}
}

the name configureauth does not exist

i'm trying this tutorial
http://httpjunkie.com/2013/311/adding-mvc-5-identity-to-an-existing-project/
but is shows me an error
Error 5 The name 'ConfigureAuth' does not exist in the current context
this is my startup.cs class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(TicketSystem.Startup))]
namespace TicketSystem
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
this is Startup.Auth.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
namespace TicketSystem.App_Start
{
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
}
}
You have different namespaces in both files: namespace TicketSystem.App_Start and namespace TicketSystem. Make sure they are the same. Or alternatively add using statement: using TicketSystem.App_Start in your startup.cs class.
If you check the example you'll see that both files are using the same namespace (namespace MVC5FullApp)

Categories

Resources