Quantcast
Channel: ASP.NET Core
Viewing all 9386 articles
Browse latest View live

Verify Code For Forgot Password in Asp.net Core

$
0
0

Hi,

in asp.net core when user click reset password ,send email to him for reset password page but
i want when user click i want send code to phone then verify it and redirect to Reset Password View for reset his password?
but in Account Controller how to generate code and then verify it for reset  his password?
how to use send code to phone instead of email ?


data-bind is successful but the actual value is not being displayed

$
0
0

public enum OwnershipType
{
Buying,
Owns,
Renting,
[AS400Value("Other")]
Boards,
[Display(Name = "Live with Relative"), AS400Value("Other")]
LiveWithRelative,
Other
}

EDIT sscreen where I select the value in teh dropdown

<div class="form-group">
<label asp-for="OwnershipType" style="float:left;margin-right:5px;"></label>
<div class="input-group col-md-6">

<select class="form-control" asp-for="OwnershipType"
asp-items="@Html.GetEnumSelectList<Ucfs.LoanPortal.Data.Entities.OwnershipType>
()" data-bind="value :ownershipType">
<option>Select</option>
</select>
<span asp-validation-for="OwnershipType"></span>
</div>
</div>

THIS IS THE DISPLAY CODE : AND RIGHT NOW IF I SELECT BUYING : IT RETURNS 0 INSTEAD OF "BUYING" 

<div class="col-md-6">
<div class="form-row">
<label class="col-md-5 col-form-label" asp-for="OwnershipType">Type Of Housing</label>
<div class="col-md">
<span class="form-control-plaintext" data-bind="text: ownershipType"></span>
</div>
</div>
</div>

PLEASE HELP ME 

Checkboxes display

$
0
0

I have the Edit screen with 

<div class="col-md-6">
<label class="col-form-label">Account Types (Select all that apply)</label>
<div>
<label asp-for="HasCheckingAccount"><input class="form-check" asp-for="HasCheckingAccount" type="checkbox" data-bind="checked: hasCheckingAccount" /> @Html.DisplayNameFor(m => m.HasCheckingAccount)</label>
</div>
<div>
<label asp-for="HasSavingsAccount"><input class="form-check" asp-for="HasSavingsAccount" type="checkbox" data-bind="checked: hasSavingsAccount" /> @Html.DisplayNameFor(m => m.HasSavingsAccount)</label>
</div>
<div>
<label asp-for="HasDebitOrCreditCard"><input class="form-check" asp-for="HasDebitOrCreditCard" type="checkbox" data-bind="checked: hasDebitOrCreditCard" /> @Html.DisplayNameFor(m => m.HasDebitOrCreditCard)</label>
</div>
</div>

When I select any of them I need to display the checked values on the screen. Right now my code is as below : but I want to display only the selected ones. 

<div class="col-md-6">
<label class="col-form-label">Account Types (Select all that apply)</label>
<div>
<label asp-for="HasCheckingAccount"><input class="form-check" asp-for="HasCheckingAccount" type="checkbox" data-bind="checked: hasCheckingAccount" /> @Html.DisplayNameFor(m => m.HasCheckingAccount)</label>
</div>
<div>
<label asp-for="HasSavingsAccount"><input class="form-check" asp-for="HasSavingsAccount" type="checkbox" data-bind="checked: hasSavingsAccount" /> @Html.DisplayNameFor(m => m.HasSavingsAccount)</label>
</div>
<div>
<label asp-for="HasDebitOrCreditCard"><input class="form-check" asp-for="HasDebitOrCreditCard" type="checkbox" data-bind="checked: hasDebitOrCreditCard" /> @Html.DisplayNameFor(m => m.HasDebitOrCreditCard)</label>
</div>
</div>

Uploading asp.net core 2.1 site to 1&1 shared hosting (windows hosting)

$
0
0
I have recently been playing around with asp.net core. I have built a site and have uploaded all the project files to my hosting account via FTP using FileZilla. When I then try to access the site I get a 403.14

I deleted the files from the server and tried to FTP it from visual studio and absolutely nothing happened. No files were uploaded.

In the end, I went back to FileZilla and re-uploaded the files but I am back to my original 403.14 error.

I probably should have said in the beginning that the site works fine when I run it on my local machine when I debug in visual studio.

Have I missed some step that I was previously unaware of? Am I being a dummy? I just don't seem to know what I am doing lol.

I have never done this before, I was up until a couple of weeks ago a webforms guy. Sadly webforms seems to be getting killed off by Microsoft, so adapt or die as they say. Sadly at this moment in time, I don't seem to be adapting all that well.

[SOLVED] Why doesn't test.html work?

Windows User and Anonymous Login

$
0
0

Hi,

I built an ASP Net Core MVC Application on IIS allowing both windows authentication an anonymous login. So far it is working as expected.

But is there a possibility, if someone calls a page, that allows anonymous login, to check if he is windows authenticated, so I can give different content

on this page then to someone who is anononympously logged in?

Regards Mario

DI question

$
0
0

I have a class which will interact with DB

public class MiscRepository
{ 
   private string _connectionString;
   public MiscRepository(string connectionString)
   {
     _connectionString = connectionString;
   }
}

I have a controller which will use MiscRepository

public class MiscController : Controller
{
   private MiscRepository _miscRepository;
   public MiscController(MiscRepository miscRepository)
   {
      _miscRepository = miscRepository;
   }
}

The connection string is in appSetting file and I guess I should be able to access it using IConfiguration

Where and how can I use IConfigurations' connection string in the Startup file?

.Net Core 2.2 debug with IIS Express gzip compressed, but not Kestrel

$
0
0

I'm converting an old webform over to .NET Core 2.2 and hit the point of doing some performance comparisons.  On my development machine, Chrome developer tools has a finish of 125ms.  The Core version 274ms.  Confused, I noticed I was using IIS Express and thought "Oh, okay, overhead for the reverse proxy", so I switched to using Kestrel.  With Kestrel I'm getting 257ms.  

I started digging to try and figure out why it's performing so much worse than the webform version and noticed IIS Express webform transferring 222 KB, IIS Express Core 224 KB, Kestrel 558 KB.  Looking at the response headers shows that Kestrel isn't compressing anything.

I've got this in ConfigureServices

 	    services.AddResponseCompression(options =>
            {
                options.EnableForHttps = true;
                options.Providers.Add<BrotliCompressionProvider>();
                options.Providers.Add<GzipCompressionProvider>();
                options.MimeTypes =
                    ResponseCompressionDefaults.MimeTypes.Concat(
                        new[] { "image/svg+xml" });
            });
            services.Configure<BrotliCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Optimal;
            });
            services.Configure<GzipCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Optimal;
            });

and this in Configure(before UseMvc)

app.UseResponseCompression();

Note, if I remove those lines, I get the same 550+ KB with IIS Express, so I know they are doing something.

WebForm with IIS Express

.NET Core 2.2 IIS Express

.NET Core 2.2 Kestrel

Am I missing something simple?  (please, only looking for why it's not working, not "it doesn't matter" opinions)


Opensource and free Administration Panel for webapplication

$
0
0

Hi all,

I wonder if there is any Opensource and free administration panel for webapplications. The best approach that I've found was the CoreUI that have a free version of their product. Therefore I wonder if there is out there any similar approach.

Cheers,

Sharing user authentication between ASP.NET Core 2.2 and WinForms

$
0
0

We have a WinForms project (.NET Framework 4.6.1) which uses a WCF service to connect to devices via MQTT.

We are building a new ASP.NET Core 2.2 project with individual authentication. What's the best way to get the authentication in the WinForms side?

I can access the database from the WinForms app, but I would like to use UserManager and SignInManager to find users (UserManager.FindByNameAsync/UserManager.FindByEmailAsync), check passwords (SignInManager.PasswordSignInAsync/_signInManager.CheckPasswordSignInAsync), register new accounts, etc.

This post makes me think it should be possible but it doesn't findApplicationUser class. Am I missing anything obvious here?

Should we go for a completely different approach and build a Web API as explained here?

Configure Active Directory group and Check if user belongs to that AD group in .Net CORE 2.2

$
0
0

Hi ,

     I'm new to the .net core and trying to authenticate only users from a Active Directory group to access the application. I have everything set up to allow only the ADGroup but the application is not able to read the appsettings not identifying the group and denying the access to the windows- Active directory users. 

appsettings.json

{"Logging": {"LogLevel": {"Default": "Debug","System": "Information","Microsoft": "Information"
    }
  },"AllowedHosts": "*", "SecuritySettings": {"ADGroup": "LSNET\\ADCAdmin"  // here is my AD group 
  }

}

Startup.cs

 public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAuthentication(HttpSysDefaults.AuthenticationScheme);
               

            services.Configure<IISServerOptions>(options =>
            {
                options.AutomaticAuthentication = true;
            });

            services.Configure<IISOptions>(options =>
            {
                options.ForwardClientCertificate = false;
            });


            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
                .AddJsonOptions(options =>
                    options.SerializerSettings.ContractResolver = new DefaultContractResolver());


            services.AddMvc(config =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();

                config.Filters.Add(new AuthorizeFilter(policy));
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("ADRoleOnly", policy => policy.RequireRole(Configuration["SecuritySettings:ADGroup"]));
            });


            // Add Kendo UI services to the services container
            services.AddKendo();
            services.AddAutoMapper();           

        }
		

ADController.cs

[Authorize(Policy = "ADRoleOnly")]
    public class ADController : Controller
    {
       //Authenticate only users from the ADGroup.
    }

 Thank you

List all users in Core 2.2

$
0
0

Hi, I am rather new to asp net core. working now in version 2.2.

With the Identity framework I try to create a site that allows only known users. So far I manege rather good, got role management working, and added some users in a Admin role. I And I can add new Users to the system. Now I want to create a razorpage that list all users known to the system.

I added a new page in Areas-Identity-Account and called it UserList.  this is my UserList.cshtml page:

@page
@model RoosterApp.Areas.Identity.Pages.UserListModel
@{
}
UserList Pagina

<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Users[0].KLMId)
</th>
<th>
@Html.DisplayNameFor(model => model.Users[0].Name)
</th>
</tr>
</thead>
<tbody>
@foreach(var item in Model.Users)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.KLMId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
<a asp-page="./Edit" asp-route-id="@item.KLMId">Edit</a> |
<a asp-page="./Details" asp-route-id="@item.KLMId">Details</a> |
<a asp-page="./Delete" asp-route-id="@item.KLMId">Delete</a>
</td>
</tr>
}
</tbody>
</table>

and this is my UserList.cshtml.cs file so far:

using Microsoft.AspNetCore.Mvc.RazorPages;
using RoosterApp.Data;
using RoosterApp.Models;
using System.Collections.Generic;

namespace RoosterApp.Areas.Identity.Pages
{

public class User
{
public string KLMId { get; set; }
public string Name { get; set; }
}

public class UserListModel : PageModel
{
//private readonly UserManager<ApplicationUser> _userManager;
public List<User> Users;

public void OnGet()
{
Users = new List<User>();
List<ApplicationUser> UserList;
var context = new ApplicationDbContext();
UserList = context.Users.UserList();  //this is not working!! also UserList = context.Users.ToList(); is not working
foreach (ApplicationUser au in UserList)
{
User U = new User();
U.KLMId = au.klmId;
U.Name = au.NormalizedUserName;
Users.Add(U);
}

}


}
}

and this is my ApplicationDBcontext:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) { }

public ApplicationDbContext()
{
}

}

The problem is that I can not get a list of users out of the ApplicationDbContext. Also applicationUser or ApplicationRole are not giving me the possibility to get a list of users. If I use UserList = context.Users.ToList() the project runs but I get a error message:

System.InvalidOperationException

 HResult=0x80131509

 Message=No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

Please Help.

Using a parameter for Custom Validation (ValidationAttribute) that exists in the model but cannot be used/exposed in the View

$
0
0

Hi All,

I have an issue where I am not sure what the best way to solve the problem.

I wrote a class derived from ValidationAttribute that takes a string (Object value) and uses the  validation context (view model parameters) to validate the string. The problem is that I have one parameter in the model that cannot be exposed on the form and I need this parameter to validate the string. I do not want to have this parameter contained on the page in any manner. Unfortunately, if the parameter is not on the page, when I retrieve the value (validationContext.ObjectType.GetProperty) it will be null. However, if I hide the parameter on the page (Html.HiddenFor), I received the parameter properly in ValidationContext.

So two questions:

  1. How can I include the parameter in the context without using it on the page?
  2. I read https://sergeyakopov.com/tamper-proof-hidden-fields-in-asp-net-mvc/ on the web, but it looks like doing something similar in Core 2.1 looks a little bit envolved. Is there an easier way to hide the parameter on the form without exposing the value?

Any suggestions are appreciated.

Thanks,

Tom

Store data in masterdb as string or id of detail table?

$
0
0

Hi all,

Here is the situation,

Lets say I need to store State and Country data in a DB.

As you know I can store it as String as is, like (California /USA) or I can store it as States's Table ID and Countries' table ID (14/81)

The thing is the stored data is only one word and I don't want to store it as id (and get it with join).

Because in SPA application it is hard to construct a page from json data (you need to store id in a hidden input and send it etc. etc.)

What do you think?

Should I afraid of using strings  to store State/Country data? Because in 10 years record count can be million and that time strings can occupy lots of space and blow the db?

thanks

Serialize navigation properties in json result

$
0
0

Hi

On my server i have a webservice rest that return one object that contain one "navigation properies" as a List<T> that is valorized with two elements.

The problem is that when is serialized, the client receives the object, but without navigation properies in json result.

if I use [DataMember()] on the navigation properies, work. The problem is that I can't use this attribute. Is possible to serialize this property without using [DataMember()]?

THANKS


Generating PDF from DOCX in asp.net core web app

$
0
0

Hi all,

I am deploying an web asp.net core application in Azure, in which i am using Microsoft.Office.Interop.Word to produce a custom PDF (the code reads a template, fill the bookmarks and save as PDF). 

The web application generates the PDF well locally but when I deploy it to Azure I get the following error: "Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."

I have been reading some articles on this, but I had this working before. Now I've updgraded the application to .net core 2.2. and now I have the following message on the project dependencies: "Package 'Microsoft.Office.Interop.Word 15.0.4797.1003' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project." 

So, is there any solution for this, using one of the following approaches (or other)?

1) solve the class registration issue in Azure?

2) change the Interop.Word version or downgrade de .net core version?

3) use a different component (for example Open XML SDK for Office - in this case is it possible to replace bookmarks of a docx and generate a PDF?)?

Thanks.

Bruno.

MVC Debugging

$
0
0

Hi, how are you doing?
I am trying to learn how to develop websites using .NET Core by way of reading a book entitled Pro ASP.NET Core MVC by Adam Freeman. In chapter 8, he's building a custom tag helper class. He then registered the tag helper in the ViewImport class. I also did the same but I really can't produce the desired output. After spending hours and hours of debugging what were wrong, I found out that i misspelled a character in my viewImport.cshtml. Even though the problem has been resolved, I really don't want to happen it again in the near future. Do you have suggestions on how I can better debug my View if something goes wrong or if the desired output is still different than expected? 

Regards

Problem when connecting to a SOAP service with .Net Core 2.0 behind a proxy

$
0
0

Hello

I'm using Visual Studio 2017

I have noticed that it was not possible to connect to a SOAP service from a .Net Core 2.0 when being behind a proxy (when connected directly to the internet it's working and when connecting through the proxy from a .Net Core 1.1 app it's working too).

I have created a little test program (Console app) that calls a public SOAP service (http://www.webservicex.net/globalweather.asmx).

By changing the target of this program (.Net Core 1.1 / .Net Core 2.0) I can reproduce the problem.

I have done a network capture (with Wireshark) and when this problem happens I can see no HTTP request coming out from my computer.

Does anybody know what is going wrong ? Maybe I am not calling this service the right way.

Thanks in advance

Insert Full Html into Razor Page or ?

$
0
0

One of my  razor pages has a full blown HTML page for a model variable

<div><pre>@Model.TheHMLText</pre></div>   -  HTMLText comes with its own head and style content....  so that just gets rendered with all the HTML tags as in 

<head>
<title></title>
<style type="text/css">  etc etc

I'm looking at @Html.RenderPartial(...)    But this function feels like it looks  static content - but mine is dynamically loaded from my model.  So....  What are my options... ??

Thanks !!!

How to assign any number of parameter keys on function getbyid repository pattern ?

$
0
0
Problem

How to assign any number of parameter keys on function Getbyid Repository pattern ?

I work on web app using repository pattern generics in  repository interface getbyid function as following
public T GetById(int Id)
        {
            return dbSet.Find(Id);
        }

and ininterface Igenerics

 T GetById(int Id)


suppose i dont know how many parameters passing so that what i do

and how to call it please .

getbyid have more than one key keys for model may be keys for model 1key or 2 or 3 or 4 etc ..


so that can you help me to do that usingdynamic datatype or paramsobject[] keyValues

public T GetById(what i write here) 
{ 
return dbSet.Find(Id); 
}



and in interface I generics

T GetById(what i write here)




when call getbyid how to call it

i need to use dynamic and param object[] key Values

What I have tried:

public T GetById(what i write here)
        {
            return dbSet.Find(Id);
        }


<

Viewing all 9386 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>