No webpage was found for the web address: https://localhost:5001/ - asp.net-core-5.0

This localhost page can’t be foundNo webpage was found for the web address: https://localhost:5001/
HTTP ERROR 404
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace CMS.WEBAPI.Controllers
{
[ApiController]
[Route("controller")]
public class CoursesController: ControllerBase
{
public CoursesController()
{
}
[HttpGet]
public string GetCourses()
{
return "hello world";
}
}
}
--
getting error as pagenot found

by changing the route attribute - working fine.
[Route("controller")]

Related

The Name 'GUILayout' does not exist in the current context

I'm doing procedural terrain generation in unity from Sebastian Lague's tutorial, and this code isn't working. How can I fix that?
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
[CustomEditor (typeof(MapGenerator))]
public class MapGeneratorEditor : Editor {
public override void OnInspectorGUI() {
MapGenerator mapGen = (MapGenerator)target;
DrawDefaultInspector ();
if (GUILayout.Button ("Generate")) {
mapGen.GenerateMap ();
}
}
}
You should also include UnityEngine namespace
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

Token Based Authentication using ASP.NET Web API 2, Owin, AspNet.Identity.MongoDB and mongocsharpdriver

+after successfully implementing Token Based Authentication using ASP.NET Web API 2, Owin, and Identity, i wished to change my implementation to use MongoDB instead of MSSQL with Entity Framework, with the help of this application here....truth be said, i dont fully understand how this should be done, but at least i know what i want my application to behave. i want to follow this IMPLEMENTATION HERE, using AspNet.Identity.MongoDB and mongocsharpdriver...and so far, here,s what I've done:
Account Controller
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using withMongoDB.HelperClasses.Services;
using withMongoDB.Models.Account;
namespace withMongoDB.Controllers
{
[RoutePrefix("api/Account")]
public class AccountsController : ApiController
{
AccountsService _accountsService = new AccountsService();
// POST api/Account/Register
[AllowAnonymous]
[Route("Register")]
public async Task<IHttpActionResult> Register(UserModel userModel)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
await _accountsService.Register(userModel);
return Ok();
}
private IHttpActionResult GetErrorResult(IdentityResult result)
{
if (result == null)
{
return InternalServerError();
}
if (!result.Succeeded)
{
if (result.Errors != null)
{
foreach (string error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
if (ModelState.IsValid)
{
// No ModelState errors are available to send, so just return an empty BadRequest.
return BadRequest();
}
return BadRequest(ModelState);
}
return null;
}
}
}
then the register method from the controller should be taken by the accounts Service
using AspNet.Identity.MongoDB;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using withMongoDB.Models.Account;
namespace withMongoDB.HelperClasses.Services
{
public class AccountsService
{
private readonly MongoAccountsConnectionHelper<UserProfile> _accounts;
public AccountsService()
{
_accounts = new MongoAccountsConnectionHelper<UserProfile>();
}
public async Task<IdentityResult> Register(UserModel userModel)
{
var userprofile = new UserProfile
{
UserName = userModel.UserName
};
var result = await _accounts.CreateAsync(userprofile, userModel.Password);
return result;
}
}
}
and finally the MongoAccountsConnectionHelper takes the result of the accounts service class to mongo database....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace withMongoDB.HelperClasses
{
using AspNet.Identity.MongoDB;
//using Entities;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Driver;
using System.Configuration;
using withMongoDB.Models.Account;
public class MongoAccountsConnectionHelper
{
private readonly MongoCollection<UserProfile> userProfileCollection;
public MongoDatabase Database { get; private set; }
public MongoAccountsConnectionHelper()
{
var pack = new ConventionPack()
{
new CamelCaseElementNameConvention(),
new EnumRepresentationConvention(BsonType.String)
};
ConventionRegistry.Register("CamelCaseConvensions", pack, t => true);
var mongoUrlBuilder = new MongoConnectionStringBuilder(ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString);
Database = new MongoClient().GetServer().GetDatabase(mongoUrlBuilder.DatabaseName);
userProfileCollection = Database.GetCollection<UserProfile>("users");
}
public MongoCollection<UserProfile> Users
{
get { return userProfileCollection; }
}
}
}
any help, tips, ideas, or opinions will be highly appreciated....{should i consider alternatives like MembershipReboot and IdentityReboot by brockallen?}
To do it smoothly, you need first to remove the dependency on "Microsoft.AspNet.Identity.EntityFramework", by providing your own user class/table (which should implements IUser as a minimum), and Also you need to implement the UserManager class (which should imeplements UserManager, and finally you need to implement the UserStore class (which should implement IUserStore as minimum) where T is the Id type in the User Table.
Once you done the above, then it is the UserStore where you can change to use MongoDB.
Hope that helps.

MEF giving CompositionException

I am new to MEF and I am trying this following program.
The class library whose dll I am making has following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition;
namespace MefTestsCore
{
[Export (typeof(MefTestsCore.IFace))]
public class CoreClass1 : IFace
{
public String getName()
{
return "CoreClass1";
}
}
interface IFace
{
String getName();
}
}
The program which wants to access the dll has following code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using MefTestsCore;
namespace MefTests
{
class Program
{
[Import (typeof(MefTestsCore.IFace), AllowRecomposition=true)]
public IFace iFaceObj;
static void Main(string[] args)
{
Program p = new Program();
p.Method();
}
public void Method()
{
DirectoryCatalog catalog = new DirectoryCatalog(#"C:\Users\username");
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
Console.WriteLine(iFaceObj.getName());
Console.ReadKey();
}
}
}
I have the MEFLibrary.dll (dll containing MefTestsCore namespace, the first part of above code) at C:\Users\username. When I run the program, it throws CompositionException with following details
The composition produced a single composition error.
The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) The export 'MefTestsCore.CoreClass1 (ContractName="MefTestsCore.IFace")' is not assignable to type 'MefTestsCore.IFace'.
Resulting in: Cannot set import 'MefTests.Program.iFaceObj (ContractName="MefTestsCore.IFace")' on part 'MefTests.Program'.
Element: MefTests.Program.iFaceObj (ContractName="MefTestsCore.IFace") --> MefTests.Program
In your test program you are using MefTestsCore. So I assume you referenced that assembly from your test program. But then you also load a copy from c:\Users\username. Now they types don't match because they come from different assemblies.
You have to put the interface into it's own assembly so that you then can reference it from your program and from MefTestsCore.

Use repository in referenced dll using entity framework

I have created a DLL that contains lots of authentication and user management that I'm trying to use in a separate project (MVC 3 Website).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestProj.Authentication;
namespace TestSite.MVC.Areas.Admin.Controllers
{
public class TestController : Controller
{
AuthenticationRepository authrep = new AuthenticationRepository();
public ActionResult Index()
{
authrep.DeleteUser(1);
return View();
}
}
}
Now this obviously does'nt work, which is understandable.
Is it dependency injection I need here?
And in that case, how would the basic code look for that?
Do I need to add something in the constructor for the referenced DLL?
Try structuring your controller like this:
public class TestController : Controller
{
IAuthenticationRepository AuthenticationRepository { get;set; }
public void TestController (IuthenticationRepository authenticationRepository)
{
this.AuthenticationRepository = authenticationRepository;
}
public ActionResult Index()
{
this.AuthenticationRepository.DeleteUser(1);
return View();
}
}
Create an interface for your repository. You could then use a DI framework (like Ninject for MVC 3) to inject instances of AuthenticationRepository into usages of IAuthenticationRepository.
https://github.com/ninject/ninject/wiki

Error when trying to populate listbox

Hi I am a student I am getting this error:
forreach statement cannot operate on
variables of type 'object' because
'object' does not contain a public
definition for 'GetEnumerator'
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string result = " ";
foreach (string activity in listBox1.SelectedItems)
{
result += activity + " ";
}
this.textBox1.Text = result;
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox2.Text);
textBox2.Clear();
}
}
}
Pl. help me
Your code works fine for me. However, your code will break if you've added something other than a string to your ListBox's Items collection (although this will produce a different error than what you're apparently seeing).
Can you add the code you use to populate this ListBox?