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

How to implement Servicehost in asp.net core 3.1

$
0
0
How to implement Servicehost in asp.net core 3.1 i am migrating asp.net project to .net core 3.1 if Servicehost is not supported then what is solution

How to get Core 2.1 Cookies Consent Message to Display

$
0
0

I started learning Core 2.1, and made use of the partial view for Cookies Consent. Things went well.

Then I changed the bootstrap file from v. 3 to v.4, and the consent message looks wonky. The navbar

collapses by default, the button is now a tiny 4 pixel barline, and the entire navbar is unformatted.

Has anyone come across this and fixed it? What did you do?

I'd be grateful for any advice on how to fix this. All my code is auto-generated. Only bootstrap changed.

OAuth2 flows using Refit with Asp Net Core 2.1

$
0
0

Well, I have a WebApi using Asp Net Core 2.1 that have some security endpoints, so I have the following:

services.AddAuthentication(options =>{
              options.DefaultAuthenticateScheme=JwtBearerDefaults.AuthenticationScheme;
              options.DefaultChallengeScheme=JwtBearerDefaults.AuthenticationScheme;}).AddJwtBearer(options =>{
              options.Authority= configuration["Authorization:Domain"];
              options.Audience= configuration["Authorization:ApiIdentifier"];
              options.TokenValidationParameters=newTokenValidationParameters(){ValidateLifetime= configuration["Authorization:ValidateLifetime"]==null?true:Boolean.Parse(configuration["Authorization:ValidateLifetime"])};
              options.RequireHttpsMetadata= configuration["Authorization:RequireHttpsMetadata"]==null?true:Boolean.Parse(configuration["Authorization:RequireHttpsMetadata"]);});

This works very well when someone calls my API, the validation is OK. I'm using http://auth0.com/ as an authorization provider.

Now I need to call other APIs that have security endpoints too, using Authorization Bearer Token (JWT). The flow that I should use in this case is Client Credentials. So, I have the steps:

  1. Someone calls my API
  2. My API validates Jwt Token using auth0.com as authorization provider
  3. I need to call other API, so I'm using Refit Library

My Refit interface:

Well, I have a WebApi using Asp Net Core 2.1 that have some security endpoints, so I have the following:

services.AddAuthentication(options =>{
              options.DefaultAuthenticateScheme=JwtBearerDefaults.AuthenticationScheme;
              options.DefaultChallengeScheme=JwtBearerDefaults.AuthenticationScheme;}).AddJwtBearer(options =>{
              options.Authority= configuration["Authorization:Domain"];
              options.Audience= configuration["Authorization:ApiIdentifier"];
              options.TokenValidationParameters=newTokenValidationParameters(){ValidateLifetime= configuration["Authorization:ValidateLifetime"]==null?true:Boolean.Parse(configuration["Authorization:ValidateLifetime"])};
              options.RequireHttpsMetadata= configuration["Authorization:RequireHttpsMetadata"]==null?true:Boolean.Parse(configuration["Authorization:RequireHttpsMetadata"]);});

This works very well when someone calls my API, the validation is OK. I'm using http://auth0.com/ as an authorization provider.

Now I need to call other APIs that have security endpoints too, using Authorization Bearer Token (JWT). The flow that I should use in this case is Client Credentials. So, I have the steps:

  1. Someone calls my API
  2. My API validates Jwt Token using auth0.com as authorization provider
  3. I need to call other API, so I'm using Refit Library

My Refit interface:

publicinterfaceIUserInfoApi{[Get("/api/v2/users/{userId}")][Headers("Authorization: Bearer")]Task<UserInfoDto>GetUserInfoAsync(string userId);}

And I created I handler to add Bearer token to my request:

//refit apis
      services.AddRefitClient<IUserInfoApi>().AddHttpMessageHandler<AuthorizationMessageHandler>().ConfigureHttpClient(c => c.BaseAddress=newUri(configuration["Api:UserInfo"]));

And my handler:

protectedoverrideasyncTask<HttpResponseMessage>SendAsync(HttpRequestMessage request,CancellationToken cancelToken){HttpRequestHeaders headers = request.Headers;AuthenticationHeaderValue authHeader = headers.Authorization;if(authHeader !=null)
        headers.Authorization=newAuthenticationHeaderValue(authHeader.Scheme, JWT_TOKEN);returnawaitbase.SendAsync(request, cancelToken);}

This works, but I think is too much manually and error-prone:

  1. There is a lot of OAuth2 flows to implement manually, to generate a token (client credentials, implicit flow, authorization code flow and others).
  2. I have to implement refresh token logic.
  3. I have to implement some logic to reuse token if the expiration time is valid yet, instead generate a new token every time (hit /token endpoint every time without needed).

I worked a lot with Spring Security framework, and I can just say: "Spring, I'm using OAuth here, so insert Bearer token in every HTTP requests, please". Spring, intercepts all requests that I set in configuration and OAuth flow is respected (Client Credentials, Authorization COde Flow, and others), it's transparent for me, I don't need wast my time with it.

There is any way to do it in Asp Net Core 2.1 or I need to implement manually the token generate flow?

What does ASP.NET Core Identity provide that I cannot do with bare IdentityServer4?

$
0
0

Hi folks,

I'm looking into removing Azure B2C from a project of mine, for reasons relating to automation and such (which B2C is not yet very compatible with), but want to keep my auth work flows the same. So, I'm looking at ASP.NET Core Identity. Currently, we use B2C to secure our REST API server. We have a React SPA that redirects to B2C for tokens that we then use to access our REST API. I would be needing to implement a self-hosted replacement for B2C, basically. I see that my options appear to include ASP.NET Core Identity and IdentityServer4.

I'm a bit confused as to what each of these projects provide, though. It seems to me that they have a ton of overlap. For example, the official ASP.NET Core Identity documentation says to use IdentityServer4 if you're trying to secure a REST API. I even see that the official Visual Studio project templates use IdentityServer4 if you choose a Web Api project template and choose to enable single account authentication. But then on the IdentityServer4 documentation I see a section explaining how to then integrate IdentityServer4 back into ASP.NET Core Identity. This circular dependency / integration has me a bit confused.

So I come here for help with clarifying this ...

If I'm using IdentityServer4, why would I maybe want to use ASP.NET Core Identity? What does Identity provide on top of IdentityServer4?

As a beginner, the documentation has me very confused. Thanks!

Null Exception Issue When Working with Jwt Token

$
0
0

Hello Microsoft Team,

When i try to login by username and password. 

null exception error occur when controller hit opt.TokenValidationParameters = new TokenValidationParameters() which is available in startup.cs .

 opt.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII
                    .GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
                    ValidateIssuer = false,
                    ValidateAudience = false
                };

Errors is

Exception has occurred: CLR/System.ArgumentNullException
An exception of type 'System.ArgumentNullException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'String reference not set to an instance of a String.'
   at System.Text.Encoding.GetBytes(String s)
   at CI.API.Startup.<ConfigureServices>b__4_4(JwtBearerOptions opt) in D:\MyProject\CI.API\Startup.cs:line 67
   at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options)
   at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name)
   at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass11_0.<Get>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)

In startup.cs

 services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(opt =>
            {
                opt.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII
                    .GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
                    ValidateIssuer = false,
                    ValidateAudience = false
                };
            });

In appsettings.json

"AppSettings":{"Token":"hey i am here"
  }

AuthController 

      [HttpPost("login")]
        public async Task<IActionResult> Login(LoginViewModel model)
        {
            var user = await _userManager.FindByNameAsync(model.UserName);
            var result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);
            if (!result.Succeeded)
            {
                return BadRequest(result);
            }

            return Ok(new
            {
                result = result,
                token = await JwtTokenGenerator(user)
            });

        }




        public async Task<string> JwtTokenGenerator(User userInfo)
        {
            var claims = new List<Claim>
            {
            new Claim(ClaimTypes.NameIdentifier,userInfo.Id),
            new Claim(ClaimTypes.Name,userInfo.UserName)
          };

            var roles = await _userManager.GetRolesAsync(userInfo);
            foreach (var role in roles)
            {
                claims.Add(new Claim(ClaimTypes.Role, role));
            }

            var securityKey = new SymmetricSecurityKey(Encoding.ASCII
            .GetBytes(_config.GetSection("AppSettings:Token").Value));
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512Signature);

            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(claims),
                Expires = DateTime.Now.AddDays(1),
                SigningCredentials = credentials
            };

            var tokenHandler = new JwtSecurityTokenHandler();

            var token = tokenHandler.CreateToken(tokenDescriptor);
            return tokenHandler.WriteToken(token);


        }

How to resize image before upload to varbinary column?

$
0
0

Hi

I'm uploading an image to a varbinary column in the database successfully. But I want to resize it before uploading.

So this is what I tried:

Guests model:

public byte[] Image { get; set; }

public string ContentType { get; set; }

ImageExtentions Class to resize the image:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace System.Drawing
{
    public static class ImageExtentions
    {
        public static Image Resize(this Image current, int maxWidth, int maxHeight)
        {
            int width, height;

            if (current.Width > current.Height)
            {
                width = maxWidth;
                height = Convert.ToInt32(current.Height * maxHeight / (double)current.Width);
            }
            else
            {
                width = Convert.ToInt32(current.Width * maxWidth / (double)current.Height);
                height = maxHeight;
            }

            var canvas = new Bitmap(width, height);

            using (var graphics = Graphics.FromImage(canvas))
            {
                graphics.CompositingQuality = CompositingQuality.HighSpeed;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                graphics.CompositingMode = CompositingMode.SourceCopy;
                graphics.DrawImage(current, 0, 0, width, height);
            }

            return canvas;
        }

        public static byte[] ToByteArray(this Image current)
        {
            using (var stream = new MemoryStream())
            {
                current.Save(stream, current.RawFormat);
                return stream.ToArray();
            }
        }
    }
}

GuestsController:

//using a lot
using System.Drawing;
namespace Proj.Controllers
{
public class GuestsController : Controller
{
private readonly ApplicationDbContext _context; public GuestsController(ApplicationDbContext context) { _context = context; } //Some code [HttpPost] [ValidateAntiForgeryToken] public async Task<IActionResult> Create([Bind("Id,Name,DoB")] Guests guest, List<IFormFile> Image) { IFormFile uploadedImage = Image.FirstOrDefault(); if (ModelState.IsValid) { foreach (var item in Image) { if (item.Length > 0) { using (var stream = new MemoryStream()) { using (Image img = Image.FromStream(uploadedImage.OpenReadStream())) { Stream ms = new MemoryStream(img.Resize(900, 1000).ToByteArray()); FileStreamResult fsr = new FileStreamResult(ms, "image/jpg"); uploadedImage.OpenReadStream().CopyTo(stream); guest.Image = stream.ToArray(); guest.ContentType = uploadedImage.ContentType; } } } } } _context.Add(guest); await _context.SaveChangesAsync();
}

But this scenario gives me this error:

List<IFormFile> does not contain a definition for 'FromStream' and no accessible extension method  'FromStream' accepting a first argument of type List<IFormFile> could be found.

How to perform this task please?

Javascript and Asp.Net Core 3.1 input check boxes broken

$
0
0

Hello,

     So I had this working in Asp.net Core 2.2 with Twitter-Bootstrap 3.3.7.  I then upgraded to Asp.net Core 3.1 and Twitter-Bootstrap 4.4.  Now I am unable to get some of my javascript functions to work.  Setting breakpoints in the javascript in Chrome and Edge, they do not get hit at all.  Though I ran the output from the web through JS Fiddle and it works perfectly fine there.  So I am at a loss for what I did to break this.

What I have is a gating function within javascript that will uncheck any check boxes that are in sequence after a check box if it is unchecked, if it is checked it will enable the next available check box, leaving the others disabled.  When I run it in IIS Express this no longer happens.

Here is the Javascript I have for one page:

//Loops through the checkboxes and disables the next ones if the previous is not checked
function changeFields(fields) {
    fields.change(function () {
        Array.prototype.reduce.call(fields, function (prev, curr) {
            curr.disabled = !prev.checked || prev.disabled;


            //If you want to uncheck remaining use this instead of above line:
            curr.checked = prev.checked ? curr.checked : false;
            curr.disabled = !prev.checked;

            return curr;
        });
    });
}

//Call the for the CharacterCraft
changeFields($(".cALScb"));
changeFields($(".cALMcb"));
changeFields($(".cBLScb"));
changeFields($(".cBLMcb"));
changeFields($(".cCLScb"));
changeFields($(".cCLMcb"));



Here is the what I have in view calling this:

<form asp-controller="CharacterCrafts" asp-action="Edit" method="post"><div class="form-horizontal"><hr />
        @Html.ValidationSummary( true, "", new { @class = "text-danger" } )<div class="col-lg-12 text-center"><b style="text-align: center; font-family: 'Times New Roman', Times, serif; font-size: x-large">@Html.DisplayFor( a => a.CharNames.CharFullName )</b><br /><b style="text-align: center; font-family: 'Times New Roman', Times, serif; font-size: large">@Html.DisplayFor( a => a.CharNames.ProfName )</b></div><br /><br /><div class="form-group"><div class="form-group row"><div class="col-lg-2">
                    @Html.Label( "Crafting Class" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Achieved" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Name" )</div><div class="col-lg-1">
                    @Html.Label( "Mastery" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Achieved" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Name" )</div><div class="col-lg-1">
                    @Html.Label( "Mastery" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Achieved" )</div><div class="col-lg-1">
                    @Html.Label( "Tier Name" )</div><div class="col-lg-1">
                    @Html.Label( "Mastery" )</div></div><div class="form-group row">
                @for ( var h = 0; h<1; h++ )
                {<div class="col-lg-2"><br /><br /><br /><b>@Html.DisplayFor( a => a.CraftListA[ h ].CraftClassName )</b><br /><br /></div><div class="form-group row col-lg-10">
                        @{ int j = 0;}
                        @for ( var i = 0; i<Model.CraftListA.Count; i++ )
                        {<input type="hidden" asp-for="@Model.CraftListA[i].CharCraftCharID" /><input type="hidden" asp-for="@Model.CraftListA[i].CharCraftClassID" /><input type="hidden" asp-for="@Model.CraftListA[i].CharCraftLevelID" /><input type="hidden" asp-for="@Model.CraftListA[i].CraftLevelTier" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListA[i].CraftLevelSet" class="cALScb" /></div><div class="col-lg-2"><b>@Html.DisplayFor( a => a.CraftListA[ i ].CraftLevelName )</b></div><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListA[i].CraftLevelMastery" class="cALMcb" /></div>
                            j++;
                            if ( j==3 )
                            {<br />
                                j=0;
                            }
                            else
                            {
                                continue;
                            }
                        }</div>
                }</div><div class="form-group row">
                @for ( var h = 0; h<1; h++ )
                {<div class="col-lg-2"><br /><br /><br /><b>@Html.DisplayFor( a => a.CraftListB[ h ].CraftClassName )</b><br /><br /></div><div class="form-group row col-lg-10">
                        @{ int j = 0;}
                        @for ( var i = 0; i<Model.CraftListB.Count; i++ )
                        {<input type="hidden" asp-for="@Model.CraftListB[i].CharCraftCharID" /><input type="hidden" asp-for="@Model.CraftListB[i].CharCraftClassID" /><input type="hidden" asp-for="@Model.CraftListB[i].CharCraftLevelID" /><input type="hidden" asp-for="@Model.CraftListB[i].CraftLevelTier" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListB[i].CraftLevelSet" class="cBLScb" /></div><div class="col-lg-2"><b>@Html.DisplayFor( a => a.CraftListB[ i ].CraftLevelName )</b></div><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListB[i].CraftLevelMastery" class="cBLMcb" /></div>
                            j++;
                            if ( j==3 )
                            {<br />
                                j=0;
                            }
                            else
                            {
                                continue;
                            }
                        }</div>
                }</div><div class="form-group row">
                @for ( var h = 0; h<1; h++ )
                {<div class="col-lg-2"><br /><br /><br /><b>@Html.DisplayFor( a => a.CraftListC[ h ].CraftClassName )</b><br /><br /></div><div class="form-group row col-lg-10">
                        @{ int j = 0;}
                        @for ( var i = 0; i<Model.CraftListC.Count; i++ )
                        {<input type="hidden" asp-for="@Model.CraftListC[i].CharCraftCharID" /><input type="hidden" asp-for="@Model.CraftListC[i].CharCraftClassID" /><input type="hidden" asp-for="@Model.CraftListC[i].CharCraftLevelID" /><input type="hidden" asp-for="@Model.CraftListC[i].CraftLevelTier" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListC[i].CraftLevelSet" class="cCLScb" /></div><div class="col-lg-2"><b>@Html.DisplayFor( a => a.CraftListC[ i ].CraftLevelName )</b></div><div class="col-lg-1"><input type="checkbox" asp-for="@Model.CraftListC[i].CraftLevelMastery" class="cCLMcb" /></div>
                            j++;
                            if ( j==3 )
                            {<br />
                                j=0;
                            }
                            else
                            {
                                continue;
                            }
                        }</div>
                }</div></div><div class="form-group row"><div class="col-lg-12 row"><div class="col-lg-3"><b>Select a Guild:</b></div>
                @for ( var i = 0; i<Model.Guild.Count; i++ )
                {<input type="hidden" asp-for="@Model.Guild[i].FactionID" /><div class="col-lg-1"><input type="checkbox" asp-for="@Model.Guild[i].isChecked" /></div><div class="col-lg-3"><b>@Html.DisplayFor( a => a.Guild[ i ].FactionName )</b></div>
                }</div></div><div class="form-group row"><div class="col-lg-12 row"><div class="col-lg-offset-2 col-lg-2"><input type="submit" value="Save" class="btn btn-secondary" /></div><div class="col-lg-5"></div><div class="col-lg-2"><a asp-controller="Menu" , asp-action="EdChar" , null, class="btn btn-danger">Cancel</a></div></div></div></div></form>

Everything displays correctly on the page, but after an unchecked check box everything is still enabled.  This can been seen in the output from Edge:

<div class="form-group"><div class="form-group row"><div class="col-lg-2"><label for="Crafting_Class">Crafting Class</label></div><div class="col-lg-1"><label for="Tier_Achieved">Tier Achieved</label></div><div class="col-lg-1"><label for="Tier_Name">Tier Name</label></div><div class="col-lg-1"><label for="Mastery">Mastery</label></div><div class="col-lg-1"><label for="Tier_Achieved">Tier Achieved</label></div><div class="col-lg-1"><label for="Tier_Name">Tier Name</label></div><div class="col-lg-1"><label for="Mastery">Mastery</label></div><div class="col-lg-1"><label for="Tier_Achieved">Tier Achieved</label></div><div class="col-lg-1"><label for="Tier_Name">Tier Name</label></div><div class="col-lg-1"><label for="Mastery">Mastery</label></div></div><div class="form-group row"><div class="col-lg-2"><br><br><br><b>Farmer</b><br><br></div><div class="form-group row col-lg-10"><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_0__CharCraftCharID" name="CraftListA[0].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_0__CharCraftClassID" name="CraftListA[0].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_0__CharCraftLevelID" name="CraftListA[0].CharCraftLevelID" value="1"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_0__CraftLevelTier" name="CraftListA[0].CraftLevelTier" value="1"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_0__CraftLevelSet" name="CraftListA[0].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Apprentice</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_0__CraftLevelMastery" name="CraftListA[0].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_1__CharCraftCharID" name="CraftListA[1].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_1__CharCraftClassID" name="CraftListA[1].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_1__CharCraftLevelID" name="CraftListA[1].CharCraftLevelID" value="5"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_1__CraftLevelTier" name="CraftListA[1].CraftLevelTier" value="2"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_1__CraftLevelSet" name="CraftListA[1].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Journeyman</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_1__CraftLevelMastery" name="CraftListA[1].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_2__CharCraftCharID" name="CraftListA[2].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_2__CharCraftClassID" name="CraftListA[2].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_2__CharCraftLevelID" name="CraftListA[2].CharCraftLevelID" value="4"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_2__CraftLevelTier" name="CraftListA[2].CraftLevelTier" value="3"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_2__CraftLevelSet" name="CraftListA[2].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Expert</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_2__CraftLevelMastery" name="CraftListA[2].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_3__CharCraftCharID" name="CraftListA[3].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_3__CharCraftClassID" name="CraftListA[3].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_3__CharCraftLevelID" name="CraftListA[3].CharCraftLevelID" value="2"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_3__CraftLevelTier" name="CraftListA[3].CraftLevelTier" value="4"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_3__CraftLevelSet" name="CraftListA[3].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Artisan</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_3__CraftLevelMastery" name="CraftListA[3].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_4__CharCraftCharID" name="CraftListA[4].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_4__CharCraftClassID" name="CraftListA[4].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_4__CharCraftLevelID" name="CraftListA[4].CharCraftLevelID" value="6"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_4__CraftLevelTier" name="CraftListA[4].CraftLevelTier" value="5"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_4__CraftLevelSet" name="CraftListA[4].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Master</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_4__CraftLevelMastery" name="CraftListA[4].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_5__CharCraftCharID" name="CraftListA[5].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_5__CharCraftClassID" name="CraftListA[5].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_5__CharCraftLevelID" name="CraftListA[5].CharCraftLevelID" value="7"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_5__CraftLevelTier" name="CraftListA[5].CraftLevelTier" value="6"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_5__CraftLevelSet" name="CraftListA[5].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Supreme</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_5__CraftLevelMastery" name="CraftListA[5].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_6__CharCraftCharID" name="CraftListA[6].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_6__CharCraftClassID" name="CraftListA[6].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_6__CharCraftLevelID" name="CraftListA[6].CharCraftLevelID" value="9"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_6__CraftLevelTier" name="CraftListA[6].CraftLevelTier" value="7"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_6__CraftLevelSet" name="CraftListA[6].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westfold</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_6__CraftLevelMastery" name="CraftListA[6].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_7__CharCraftCharID" name="CraftListA[7].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_7__CharCraftClassID" name="CraftListA[7].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_7__CharCraftLevelID" name="CraftListA[7].CharCraftLevelID" value="3"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_7__CraftLevelTier" name="CraftListA[7].CraftLevelTier" value="8"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_7__CraftLevelSet" name="CraftListA[7].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Eastenmnet</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_7__CraftLevelMastery" name="CraftListA[7].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListA_8__CharCraftCharID" name="CraftListA[8].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListA_8__CharCraftClassID" name="CraftListA[8].CharCraftClassID" value="2"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListA_8__CharCraftLevelID" name="CraftListA[8].CharCraftLevelID" value="8"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListA_8__CraftLevelTier" name="CraftListA[8].CraftLevelTier" value="9"><div class="col-lg-1"><input type="checkbox" class="cALScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListA_8__CraftLevelSet" name="CraftListA[8].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westemnet</b></div><div class="col-lg-1"><input type="checkbox" class="cALMcb" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListA_8__CraftLevelMastery" name="CraftListA[8].CraftLevelMastery" value="true"></div><br></div></div><div class="form-group row"><div class="col-lg-2"><br><br><br><b>Scholar</b><br><br></div><div class="form-group row col-lg-10"><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_0__CharCraftCharID" name="CraftListB[0].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_0__CharCraftClassID" name="CraftListB[0].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_0__CharCraftLevelID" name="CraftListB[0].CharCraftLevelID" value="1"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_0__CraftLevelTier" name="CraftListB[0].CraftLevelTier" value="1"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_0__CraftLevelSet" name="CraftListB[0].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Apprentice</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_0__CraftLevelMastery" name="CraftListB[0].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_1__CharCraftCharID" name="CraftListB[1].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_1__CharCraftClassID" name="CraftListB[1].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_1__CharCraftLevelID" name="CraftListB[1].CharCraftLevelID" value="5"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_1__CraftLevelTier" name="CraftListB[1].CraftLevelTier" value="2"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_1__CraftLevelSet" name="CraftListB[1].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Journeyman</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_1__CraftLevelMastery" name="CraftListB[1].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_2__CharCraftCharID" name="CraftListB[2].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_2__CharCraftClassID" name="CraftListB[2].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_2__CharCraftLevelID" name="CraftListB[2].CharCraftLevelID" value="4"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_2__CraftLevelTier" name="CraftListB[2].CraftLevelTier" value="3"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_2__CraftLevelSet" name="CraftListB[2].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Expert</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_2__CraftLevelMastery" name="CraftListB[2].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_3__CharCraftCharID" name="CraftListB[3].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_3__CharCraftClassID" name="CraftListB[3].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_3__CharCraftLevelID" name="CraftListB[3].CharCraftLevelID" value="2"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_3__CraftLevelTier" name="CraftListB[3].CraftLevelTier" value="4"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_3__CraftLevelSet" name="CraftListB[3].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Artisan</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_3__CraftLevelMastery" name="CraftListB[3].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_4__CharCraftCharID" name="CraftListB[4].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_4__CharCraftClassID" name="CraftListB[4].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_4__CharCraftLevelID" name="CraftListB[4].CharCraftLevelID" value="6"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_4__CraftLevelTier" name="CraftListB[4].CraftLevelTier" value="5"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_4__CraftLevelSet" name="CraftListB[4].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Master</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_4__CraftLevelMastery" name="CraftListB[4].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_5__CharCraftCharID" name="CraftListB[5].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_5__CharCraftClassID" name="CraftListB[5].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_5__CharCraftLevelID" name="CraftListB[5].CharCraftLevelID" value="7"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_5__CraftLevelTier" name="CraftListB[5].CraftLevelTier" value="6"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_5__CraftLevelSet" name="CraftListB[5].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Supreme</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_5__CraftLevelMastery" name="CraftListB[5].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_6__CharCraftCharID" name="CraftListB[6].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_6__CharCraftClassID" name="CraftListB[6].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_6__CharCraftLevelID" name="CraftListB[6].CharCraftLevelID" value="9"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_6__CraftLevelTier" name="CraftListB[6].CraftLevelTier" value="7"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_6__CraftLevelSet" name="CraftListB[6].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westfold</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_6__CraftLevelMastery" name="CraftListB[6].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_7__CharCraftCharID" name="CraftListB[7].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_7__CharCraftClassID" name="CraftListB[7].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_7__CharCraftLevelID" name="CraftListB[7].CharCraftLevelID" value="3"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_7__CraftLevelTier" name="CraftListB[7].CraftLevelTier" value="8"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_7__CraftLevelSet" name="CraftListB[7].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Eastenmnet</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_7__CraftLevelMastery" name="CraftListB[7].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListB_8__CharCraftCharID" name="CraftListB[8].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListB_8__CharCraftClassID" name="CraftListB[8].CharCraftClassID" value="7"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListB_8__CharCraftLevelID" name="CraftListB[8].CharCraftLevelID" value="8"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListB_8__CraftLevelTier" name="CraftListB[8].CraftLevelTier" value="9"><div class="col-lg-1"><input type="checkbox" class="cBLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListB_8__CraftLevelSet" name="CraftListB[8].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westemnet</b></div><div class="col-lg-1"><input type="checkbox" class="cBLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListB_8__CraftLevelMastery" name="CraftListB[8].CraftLevelMastery" value="true"></div><br></div></div><div class="form-group row"><div class="col-lg-2"><br><br><br><b>Weaponsmith</b><br><br></div><div class="form-group row col-lg-10"><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_0__CharCraftCharID" name="CraftListC[0].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_0__CharCraftClassID" name="CraftListC[0].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_0__CharCraftLevelID" name="CraftListC[0].CharCraftLevelID" value="1"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_0__CraftLevelTier" name="CraftListC[0].CraftLevelTier" value="1"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_0__CraftLevelSet" name="CraftListC[0].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Apprentice</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_0__CraftLevelMastery" name="CraftListC[0].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_1__CharCraftCharID" name="CraftListC[1].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_1__CharCraftClassID" name="CraftListC[1].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_1__CharCraftLevelID" name="CraftListC[1].CharCraftLevelID" value="5"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_1__CraftLevelTier" name="CraftListC[1].CraftLevelTier" value="2"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_1__CraftLevelSet" name="CraftListC[1].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Journeyman</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_1__CraftLevelMastery" name="CraftListC[1].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_2__CharCraftCharID" name="CraftListC[2].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_2__CharCraftClassID" name="CraftListC[2].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_2__CharCraftLevelID" name="CraftListC[2].CharCraftLevelID" value="4"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_2__CraftLevelTier" name="CraftListC[2].CraftLevelTier" value="3"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_2__CraftLevelSet" name="CraftListC[2].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Expert</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_2__CraftLevelMastery" name="CraftListC[2].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_3__CharCraftCharID" name="CraftListC[3].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_3__CharCraftClassID" name="CraftListC[3].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_3__CharCraftLevelID" name="CraftListC[3].CharCraftLevelID" value="2"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_3__CraftLevelTier" name="CraftListC[3].CraftLevelTier" value="4"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_3__CraftLevelSet" name="CraftListC[3].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Artisan</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_3__CraftLevelMastery" name="CraftListC[3].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_4__CharCraftCharID" name="CraftListC[4].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_4__CharCraftClassID" name="CraftListC[4].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_4__CharCraftLevelID" name="CraftListC[4].CharCraftLevelID" value="6"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_4__CraftLevelTier" name="CraftListC[4].CraftLevelTier" value="5"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_4__CraftLevelSet" name="CraftListC[4].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Master</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_4__CraftLevelMastery" name="CraftListC[4].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_5__CharCraftCharID" name="CraftListC[5].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_5__CharCraftClassID" name="CraftListC[5].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_5__CharCraftLevelID" name="CraftListC[5].CharCraftLevelID" value="7"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_5__CraftLevelTier" name="CraftListC[5].CraftLevelTier" value="6"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_5__CraftLevelSet" name="CraftListC[5].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Supreme</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_5__CraftLevelMastery" name="CraftListC[5].CraftLevelMastery" value="true"></div><br><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_6__CharCraftCharID" name="CraftListC[6].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_6__CharCraftClassID" name="CraftListC[6].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_6__CharCraftLevelID" name="CraftListC[6].CharCraftLevelID" value="9"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_6__CraftLevelTier" name="CraftListC[6].CraftLevelTier" value="7"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_6__CraftLevelSet" name="CraftListC[6].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westfold</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" checked="checked" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_6__CraftLevelMastery" name="CraftListC[6].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_7__CharCraftCharID" name="CraftListC[7].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_7__CharCraftClassID" name="CraftListC[7].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_7__CharCraftLevelID" name="CraftListC[7].CharCraftLevelID" value="3"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_7__CraftLevelTier" name="CraftListC[7].CraftLevelTier" value="8"><div class="col-lg-1"><input type="checkbox" class="cCLScb" checked="checked" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_7__CraftLevelSet" name="CraftListC[7].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Eastenmnet</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_7__CraftLevelMastery" name="CraftListC[7].CraftLevelMastery" value="true"></div><input type="hidden" data-val="true" data-val-required="The CharCraftCharID field is required." id="CraftListC_8__CharCraftCharID" name="CraftListC[8].CharCraftCharID" value="1"><input type="hidden" data-val="true" data-val-required="The CharCraftClassID field is required." id="CraftListC_8__CharCraftClassID" name="CraftListC[8].CharCraftClassID" value="9"><input type="hidden" data-val="true" data-val-required="The CharCraftLevelID field is required." id="CraftListC_8__CharCraftLevelID" name="CraftListC[8].CharCraftLevelID" value="8"><input type="hidden" data-val="true" data-val-required="The CraftLevelTier field is required." id="CraftListC_8__CraftLevelTier" name="CraftListC[8].CraftLevelTier" value="9"><div class="col-lg-1"><input type="checkbox" class="cCLScb" data-val="true" data-val-required="The CraftLevelSet field is required." id="CraftListC_8__CraftLevelSet" name="CraftListC[8].CraftLevelSet" value="true"></div><div class="col-lg-2"><b>Westemnet</b></div><div class="col-lg-1"><input type="checkbox" class="cCLMcb" data-val="true" data-val-required="The CraftLevelMastery field is required." id="CraftListC_8__CraftLevelMastery" name="CraftListC[8].CraftLevelMastery" value="true"></div><br></div></div></div>

Ideally from the output the very last check box should be disabled, but it is not.  Though if I go to JS Fiddle, this works as such: https://jsfiddle.net/MikeRM2/bzfcme06/

So this leads to wondering what went wrong, as it works in JS Fiddle but not on the actual site.  I am not getting any errors in the console or debug.  Any thoughts on why this is not working anymore would be appreciated.

Problem with relationship between User (testTaker) and Question while writin LINQ in action

$
0
0

Hi guys,

I develop Quiz application where users can login and take test. My problem is that I cannot write right action in controller so that when each user submit their answer while they are logged in, and if it's true, the relevant question score for each user must be saved in database.  Each user holds testTakerId , and there is many-to-many relationship between TestTaker and Question object as all test takers will have many questions and each question will concern all test takers. So, considering this, my model is like this:

Question

 public class Question
    {
        public Question()
        {
            Answers = new HashSet<Answer>();
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public Exam Exam { get; set; }
        public int ExamId { get; set; }
        public TimeSpan? Remainedtime { get; set; }
        public int Score { get; set; }
        public ICollection<Answer> Answers { get; set; }
        public ICollection<UserQuestion> UserQuestions { get; set; }

    }    

ExamUser

 public class ExamUser: IdentityUser
    {
        public TestTaker TestTaker { get; set; }
        public int? TestTakerId { get; set; }
    }

TestTaker

 public class TestTaker
    {
        public int Id { get; set; }
        [Required]
        public string Name { get; set; }
        public string Phone { get; set; }
        public string Education { get; set; }
        public string Job { get; set; }
        public DateTime Birth { get; set; }
        public ExamUser ExamUser { get; set; }
        public int Result { get; set; }
        public ICollection<UserQuestion> UserQuestions { get; set; }
    }

UserQuestion (moderate table for many-to-many relationship)

 public class UserQuestion
    {
        public int TestTakerId { get; set; }
        public TestTaker TestTaker { get; set; }
        public int QuestionId { get; set; }
        public Question Question { get; set; }
    }

The reason why I didn't connect ExamUser directly to questions is that its built in Id is string (it might cause problem while inserting to database).

in DbContext:

  public class IntellectDbContext:IdentityDbContext<ExamUser>
    {
        public IntellectDbContext(DbContextOptions<IntellectDbContext> dbContextOptions) : base(dbContextOptions)
        {

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<UserQuestion>()
                .HasKey(a => new { a.TestTakerId, a.QuestionId });

            modelBuilder.Entity<UserQuestion>()
                .HasOne(a => a.TestTaker)
                .WithMany(b => b.UserQuestions)
                .HasForeignKey(a => a.TestTakerId);

            modelBuilder.Entity<UserQuestion>()
                .HasOne(a => a.Question)
                .WithMany(c => c.UserQuestions)
                .HasForeignKey(a => a.QuestionId);
        }

        public DbSet<Answer> Answers { get; set; }
        public DbSet<Question> Questions { get; set; }
        public DbSet<Exam> Exams { get; set; }
        public DbSet<ExamUser> ExamUsers { get; set; }
        public DbSet<UserQuestion> UserQuestions { get; set; }
        public DbSet<TestTaker> TestTakers { get; set; }
    }

Question View in Exam:

@model Intellect.Models.ViewModels.AdminViewModel
<div class="questioncontainer"> <form asp-action="Question" asp-controller="Home" asp-route-id="@Model.NextQuestion.Id" asp-route-count="@ViewBag.Equestions"><div class="row"><div class="col-lg-3"></div><div class="col-lg-6 col-sm-12"><table><tr><th>Timer</th></tr><tr><td><label asp-for="Question.Remainedtime" id="time"></label><input type="hidden" id="timehidden" asp-for="Question.Remainedtime" /></td></tr></table><div class="question">@Model.CurrentQuestion.Description </div></div><div class="col-lg-3"></div></div><div class="row"><div class="col-lg-3 col-sm-0"></div> @{ int n = 0; } @foreach (Answer item in Model.Answers) { if (n == 0 || n == 2) { @: <div class="col-lg-3 col-sm-12"> @: <div class="firstpart"> }<input asp-for="@item.Id" name="@item.Id" hidden /><input type="radio" asp-for="@item.Id" name="myanswer" value="@item.Id" />@item.Description<br> if (n == 1 || n == 3) { @:</div> @:</div> } n++; }<div class="col-lg-3"></div></div><div class="row"><div class="col-lg-6 col-sm-4"></div><div class="col-lg-3 col-sm-4"></div><div class="col-lg-3 col-sm-4"><div class="nextbtn"> @if (ViewBag.Equestions == 0) {<input type="submit" value="Finish" /> } else {<input type="submit" value="Next" /> }</div></div></div></form></div> @section Script{ <script> var start = Date.now(), diff, seconds; function startTimer(duration) { function timer() { // get the number of seconds that have elapsed since // startTimer() was called diff = duration - (((Date.now() - start) / 1000) | 0); // does the same job as parseInt truncates the float seconds = diff; seconds = seconds < 10 ? "0" + seconds : seconds;$("#time").text(seconds);$("#timehidden").val(seconds); if (diff <= 0) { // add one second so that the count down starts at the full duration start = Date.now() + 1000; } }; // we don't want to wait a full second before the timer starts timer(); setInterval(timer, 1000); } window.onload = function () { var minute = 60 * @Model.Question.Remainedtime; startTimer(fiveMinutes); $("#time").val("start"); };</script> }

And finally, Controller (the problem is here)

 public class HomeController : Controller
    {
        private readonly IntellectDbContext _intellectDbContext;
        private readonly UserManager<ExamUser> _userManager;
        private readonly SignInManager<ExamUser> _signInManager;
        static int exam_id = 0;
        static int? PreviousId = 0;
        static int result = 0;
        static int correctAnswer = 0;
        static List<Question> RemainedQuestions = new List<Question>();
        static List<int> trueAnswers = new List<int>();

        public HomeController(IntellectDbContext intellectDbContext, UserManager<ExamUser> userManager, SignInManager<ExamUser> signInManager)
        {
            _intellectDbContext = intellectDbContext;
            _userManager = userManager;
            _signInManager = signInManager;
        }
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult About()
        {
            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [HttpGet]
        public async Task<IActionResult> Test(int Id)
        {
            exam_id = Id;
            AdminViewModel admodel = new AdminViewModel();
            admodel.Equestions = await _intellectDbContext.Questions.Include(q => q.Answers).Where(q => q.ExamId == Id).ToListAsync();
            admodel.CurrentQuestion = await _intellectDbContext.Questions.Where(q => q.ExamId == Id).FirstOrDefaultAsync();
            RemainedQuestions = admodel.Equestions;
            PreviousId = admodel.CurrentQuestion.Id;
            return View(admodel);
        }

        public async Task<IActionResult> Question(int Id, int count, int myanswer)
        {
            AdminViewModel admodel = new AdminViewModel();
            admodel.CurrentQuestion = await _intellectDbContext.Questions.Where(x => x.Id == Id).SingleOrDefaultAsync();
            admodel.Answers = await _intellectDbContext.Answers.Where(y => y.QuestionId == Id).ToListAsync();
            admodel.Equestions = await _intellectDbContext.Questions.Where(q => q.ExamId == exam_id).ToListAsync();
            admodel.CurrentQuestion.Remainedtime = new TimeSpan(0, 0, 60);

            correctAnswer = _intellectDbContext.Answers.Where(a => a.QuestionId == PreviousId && a.Correct == true).SingleOrDefault().Id;

            if(myanswer == correctAnswer)
            {
                result = int.Parse(admodel.Question.Remainedtime.ToString());
                // admodel.CurrentQuestion.Score = result;
            }

            if (_signInManager.IsSignedIn(User))
            {
                ExamUser examTaker = await _userManager.GetUserAsync(HttpContext.User);
                examTaker.TestTaker = await _intellectDbContext.TestTakers.FirstOrDefaultAsync();
                examTaker.TestTaker.UserQuestions = await _intellectDbContext.UserQuestions.ToListAsync();
                admodel.CurrentQuestion = examTaker.TestTaker.UserQuestions.Select(u => u.Question).Where(x => x.Id == Id).SingleOrDefault();admodel.CurrentQuestion.Score = result;
            }

                if (count > 1)
            {
                var question = RemainedQuestions.Single(r => r.Id == admodel.CurrentQuestion.Id);
                PreviousId = question.Id;
                RemainedQuestions.Remove(question);
                admodel.NextQuestion = RemainedQuestions[0];
                count -= 1;
            }
            else
            {
                admodel.NextQuestion = RemainedQuestions[0];
                count -= 1;
            }

            if(count == -1)
            {
                return RedirectToAction(nameof(Finish));
            }

            ViewBag.Equestions = count;

            return View(admodel);
        }
        
       
        }

Please, mainly focus on Question action as this action will do the main job. Result is calculated according to remianed time which will be the question's point. First, while running application, the code I highlighted (admodel.CurrentQuestion.Score = result;) gives null reference exception though I defined it in the code line before it. As moderate table (UserQuestion) shows only Ids in its table in SQLServer, I cannot see actually where each user's question score might be inserted. Only if joining these 3 tables, maybe we can see result if action is done successfully. How can I solve it? Has anyone faced such experience? 

Hope, one of you can find solution to this problem. Thanks in advance!


TcpClient connection slower than .NET?

$
0
0

Before I start wasting time with code a quick summary.
I wrote a HttpClient for some remote service we have to connect to.
Wrote it all in a NET Standard 2.0 library and then wrote two console apps which utilize the library to create an instance of the client and then connect to that server using TLS...client cert and eventually send and receive data.
To my surprise after they both create an instance the connect call in a NET Core app is always 100ms slower. 
NET console -> 200ms, Core 300ms. Every damn time. Same code.
Now this isn't anything terrible or something that's probably gonna kill us(we are expecting thousands of call though) but I was quite surprised.
Does anyone know if there's a setting or something that could at least bring the speed to .NET average times? Perhaps there are some defaults that are different in TcpClient itself in NET Core which specifically prevent it from connecting as fast?
I really was expecting .NET Core to be faster or at least just as fast here since it doesn't have the burden of supporting old code.

Asp.net core thread safe global variable

$
0
0

I have a .net core razor app that has a special use case where I need to have a global counter that will be incremented by every request, and yet it should remain thread-safe.

Also at web application load, this counter will be read from a database using entity framework.

I don't think that static variables are threadsafe for this scenario (since it can be read by a request then be modified after another request read its previous value)

So I was wondering if a locking mechanism is needed, or should a concurrent dictionary with a Lazy<T> be used ?

Why I can't match the .html suffix in router?

$
0
0

I want to match the .html suffix.

For example, the default index page is 

https://localhost:44354/home/index

I want to match this URL also

https://localhost:44354/home/index.html

I added these codes in startup.cs

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}.html/{id?}");
});

After the program ran, it reports this error:

An unhandled exception occurred while processing the request.
AmbiguousMatchException: The request matched multiple endpoints. Matches:

WebApplication1.Controllers.HomeController.Index (WebApplication1)
WebApplication1.Controllers.HomeController.Privacy (WebApplication1)
WebApplication1.Controllers.HomeController.Error (WebApplication1)
Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState)

Stack Query Cookies Headers Routing
AmbiguousMatchException: The request matched multiple endpoints. Matches: WebApplication1.Controllers.HomeController.Index (WebApplication1) WebApplication1.Controllers.HomeController.Privacy (WebApplication1) WebApplication1.Controllers.HomeController.Error (WebApplication1)
Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ReportAmbiguity(CandidateState[] candidateState)
Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.ProcessFinalCandidates(HttpContext httpContext, CandidateState[] candidateState)
Microsoft.AspNetCore.Routing.Matching.DefaultEndpointSelector.Select(HttpContext httpContext, CandidateState[] candidateState)
Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.MatchAsync(HttpContext httpContext)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.TryServeStaticFile(HttpContext context, string contentType, PathString subPath)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Show raw exception details

Why it matched multiple endpoints? How can I solve it? Thank you.

How to Display popup from external html file?

$
0
0

Hi

In my view, i have button which display a popup from external html as template. here is my code :

my view code :

<button type="button" id="btnNew" class="btn btn-success btn-sm" onclick="showDialog()">Create new</button><div id="divPopup"></div>

Here is my javascript function (showDialog) :

function showDialog() {    $('#divPopup').load('/Templates/ModalForm1.html');$('#myModal').modal('show');
}

And here is my external html file (ModalForm1.html) :

<!-- Modal --><div id="myModal" class="modal fade" role="dialog" data-backdrop="static"><div class="modal-dialog"><!-- Modal content--><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title">New order</h4></div><div id="myModalBody" class="modal-body"><p>Some text in the modal.</p></div></div></div></div>

But my code not working correctly. Can anybody help me how to solve my problem?

Thanks in advance

Upload image or multiple using razor page only, no code behind

$
0
0

I know how to use sql server in razor, just quick example:

@page
@using System.Data.SqlClient

@using System.Collections.Generic;
@using System.Data;
@using System.Linq;
@using System.Threading.Tasks;


@using Microsoft.AspNetCore.Http
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration

@{
    Layout = null;
}

@{

    var name = string.Empty;
    var submitset = string.Empty;
    if (Request.HasFormContentType)
    {
        name = Request.Form["name"];
        @if (string.IsNullOrEmpty(name))
        {
            name = "%";
        }
    }

    if (!string.IsNullOrEmpty(name))
    {
        var thisoffset = 0;
        var connectionString = Configuration.GetConnectionString("DefaultConnection");
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM pets WHERE petname LIKE @lastname ORDER BY petname OFFSET " + thisoffset + " ROWS FETCH NEXT 5 ROWS ONLY", conn);

            cmd.Parameters.AddWithValue("@lastname", name + "%");

            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {

                var vpetid = @reader["petid"];<div>@reader["petname"]</div><div>@String.Format("{0:MM/dd/yyyy }", reader["odate"])</div>
                int vocheck = 0;
                var mybool = (reader.GetBoolean(reader.GetOrdinal("ocheck")));
                if (mybool == true)
                {
                    vocheck = 1;
                }<div>@vocheck</div><br /><div><a href="editpet?id=@vpetid">test</a></div>




            }


        }
    }
    else
    {
        <form method="post"><div>Name: <input name="name" /></div><div><input type="submit" name="submit" /></div></form>
    }
}

But my question, using sql server and razor only, how to do image uploads?

Meaning have one page to add data, and post to another a razor page and perform upload and save operation.  No "model" code behind.

Just razor only.

Optimisation of Reverse Proxy

$
0
0

Hi guys,

So I am currently working on implementing a new project I am using MVC .NET Core 3.1 to do all of my developments.

I have a requirement to create a reverse proxy which all of my client side applications will connect to. The one I am having the biggest issue with is a connection to an on premise Analysis Services Instance, because the response content can get quite large it results in slow response times for my client.

Here is the code that I have:

using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace SSASProxyTest2
{
    public class ReverseProxyMiddleware
    {
        private static readonly HttpClient _httpClient = new HttpClient();
        private readonly RequestDelegate _nextMiddleware;

        public ReverseProxyMiddleware(RequestDelegate nextMiddleware)
        {
            _nextMiddleware = nextMiddleware;
        }

        public async Task Invoke(HttpContext context)
        {
            var targetUri = BuildTargetUri(context.Request);

            if (targetUri != null)
            {
                var targetRequestMessage = CreateTargetMessage(context, targetUri);


                using (var responseMessage = await _httpClient.SendAsync(targetRequestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted))
                {
                    context.Response.StatusCode = (int)responseMessage.StatusCode;
                    CopyFromTargetResponseHeaders(context, responseMessage);
                    await responseMessage.Content.CopyToAsync(context.Response.Body);
                }
                return;
            }
            await _nextMiddleware(context);
        }

        private HttpRequestMessage CreateTargetMessage(HttpContext context, Uri targetUri)
        {
            var requestMessage = new HttpRequestMessage();
            CopyFromOriginalRequestContentAndHeaders(context, requestMessage);
            String username = "username";
            String password = "password";
            String encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
            requestMessage.Headers.Add("Authorization", "Basic " + encoded);

            requestMessage.RequestUri = targetUri;
            requestMessage.Headers.Host = targetUri.Host;
            requestMessage.Method = GetMethod(context.Request.Method);

            return requestMessage;
        }

        private void CopyFromOriginalRequestContentAndHeaders(HttpContext context, HttpRequestMessage requestMessage)
        {
            var requestMethod = context.Request.Method;

            if (!HttpMethods.IsGet(requestMethod) &&
              !HttpMethods.IsHead(requestMethod) &&
              !HttpMethods.IsDelete(requestMethod) &&
              !HttpMethods.IsTrace(requestMethod))
            {
                var streamContent = new StreamContent(context.Request.Body);
                requestMessage.Content = streamContent;
            }

            foreach (var header in context.Request.Headers)
            {
                requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray());
            }
        }

        private void CopyFromTargetResponseHeaders(HttpContext context, HttpResponseMessage responseMessage)
        {
            foreach (var header in responseMessage.Headers)
            {
                context.Response.Headers[header.Key] = header.Value.ToArray();
            }

            foreach (var header in responseMessage.Content.Headers)
            {
                context.Response.Headers[header.Key] = header.Value.ToArray();
            }
            context.Response.Headers.Remove("transfer-encoding");
        }
        private static HttpMethod GetMethod(string method)
        {
            if (HttpMethods.IsDelete(method)) return HttpMethod.Delete;
            if (HttpMethods.IsGet(method)) return HttpMethod.Get;
            if (HttpMethods.IsHead(method)) return HttpMethod.Head;
            if (HttpMethods.IsOptions(method)) return HttpMethod.Options;
            if (HttpMethods.IsPost(method)) return HttpMethod.Post;
            if (HttpMethods.IsPut(method)) return HttpMethod.Put;
            if (HttpMethods.IsTrace(method)) return HttpMethod.Trace;
            return new HttpMethod(method);
        }

        private Uri BuildTargetUri(HttpRequest request)
        {
            Uri targetUri = new Uri("https://Example.com/msmdpump.dll");

            return targetUri;
        }
    }
}

As you can see I am taking the original request changing the target, adding credentials then returning the response.

This is where the block seems to be on large requests:

await responseMessage.Content.CopyToAsync(context.Response.Body);

This is going to be MiddelWare in my application. For completeness my startupclass has this:

 app.Map("/api/test", api =>
            {
                api.UseMiddleware<ReverseProxyMiddleware>();
            });

Can anyone tell me if this can be optimised further to deal with large responses?

Really appreciate any help.

Joe

Add items to a list from view model

$
0
0

Hey how's it going,

I'm working on a deck builder for a card game. My rough build is up on https://chronoclashdeckbuilder.azurewebsites.net/DeckBuilder and I have the project on my github https://github.com/Zami77/ChronoClashDeckBuilder

The idea is to click the images that are on the deck builder page and have them be dynamically added to a list. Once the list is complete I could then have it be saved to my SQL database tied to a user account. I'm focusing just on one step at a time, and I'd like to be able to dynamically add and remove cards from the list and have them be displayed to the user. I'll post what I think are the relevant code sections, but if it feels something is missing please check out my github. Thanks in advance for any help!

DeckBuilder View Index.cshtml

@model ChronoClashDeckBuilder.Models.ViewModels.DeckBuilderListViewModel

@{
    ViewData["Title"] = "Deck Builder";
}<h1>Deck Builder!</h1><p>Still have to implement picking a card and adding to deck.</p><p><a class="badge-dark" asp-area="" asp-controller="DeckBuilder" asp-action="Index" asp-route-curDeck="@Model.NewDeck">Display Deck</a></p><tbody>
    @foreach (var item in Model.NewDeck)
    {<tr><td>
                @item.CardName</td></tr>
    }</tbody><tbody>
    @foreach (var item in Model.Cards)
    {<tr><td><input type="image" src="~/Images/Chrono Clash Card Images/Naruto Set 1/@item.CardImage"
                       alt="@item.CardName"
                       style="width:136px;height:185px;" />
                @*How to add from viewlist to razor page, check javascript
                asp-action="@model.newdeck.add(item)"*@</td></tr>
    }</tbody>

DeckBuilderController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChronoClashDeckBuilder.Models;
using Microsoft.AspNetCore.Mvc;

namespace ChronoClashDeckBuilder.Controllers
{
    public class DeckBuilderController : Controller
    {
        private ICardRepository repository;
        public DeckBuilderController(ICardRepository repo)
        {
            repository = repo;
        }
        public IActionResult Index(List<Card> curDeck, Card cardToAdd)
        {
            if (cardToAdd != null)
                curDeck.Add(cardToAdd);

            return View(new Models.ViewModels.DeckBuilderListViewModel
            {
                Cards = repository.Cards,
                NewDeck = curDeck
            });
        }
    }
}

Models Card.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ChronoClashDeckBuilder.Models
{
    public partial class Card
    {
        [Key]
        [StringLength(20)]
        public string CardNumber { get; set; }
        [StringLength(20)]
        public string CardSet { get; set; }
        [StringLength(20)]
        public string CardType { get; set; }
        [StringLength(100)]
        public string CardImage { get; set; }
        [StringLength(10)]
        public string CardColor { get; set; }
        public int? CardCost { get; set; }
        public int? CardStrength { get; set; }
        [StringLength(80)]
        public string CardName { get; set; }
        [StringLength(200)]
        public string CardAbilities { get; set; }
        [StringLength(200)]
        public string CardStackAbilities { get; set; }
    }
}

ViewModels DeckBuilderListViewModel.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ChronoClashDeckBuilder.Models.ViewModels
{
    public class DeckBuilderListViewModel
    {
        public IEnumerable<Card> Cards { get; set; }
        public List<Card> NewDeck { get; set; }
    }
}


EntityFrameworkCore - Class with many list of the same class

$
0
0

Hi guys,

I have following class that have many List of the same classes :

public class EmailMessage
    {

        #region Lists

        
        public List<EmailAddress> FromAddresses { get; set; }
        public List<EmailAddress> BccAddresses { get; set; }
        #endregion

        [Key]
        public int Id { get; set; }
        public string MessageId { get; set; }
        public uint Uid { get; set; }
        public DateTimeOffset Date { get; set; }
        public MessageImportance Importance { get; set; }
        public MessagePriority Priority { get; set; }
        public string Subject { get; set; }
        public string Body { get; set; }
        public bool IsHtml { get; set; } = true;
        public bool NeedReadReceipt { get; set; }
        public bool NeedDeliveredReceipt { get; set; }
        public string InReplyTo { get; set; }
        public string Sender { get; set; }
        public EmailMessageDirection  MessageDirection { get; set; }
        public User User { get; set; }

    }
 public class EmailAddress
    {
        private string _name;

        public EmailAddress(EmailAddress address)
        {
            _name = address.Name;
            Address = address.Address;
        }
        public EmailAddress(string name, string address)
        {
            _name = name;
            Address = address;
        }

        [Key]
        public int Id { get; set; }
        public string Name
        {
            get
            {
                if (string.IsNullOrEmpty(_name))
                {
                    return Address;
                }
                return _name;
            }
            set
            {
                _name = value;
            }
        }
        public string Address { get; set; }

        
        public EmailMessage FromEmailMessage { get; set; }
        
        public EmailMessage BccEmailMessage { get; set; }
        

    }

My data Context is following:

        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity<EmailMessage>()
                .HasMany(em => em.FromAddresses)
                .WithOne(fa => fa.FromEmailMessage)
                .IsRequired();


            builder.Entity<EmailMessage>()
                .HasMany(em => em.BccAddresses)
                .WithOne(fa => fa.BccEmailMessage)
                .IsRequired();

        }

When I do the migration it build only one Email Address Table with following Shadow properties:

FromEmailMessageId and BccEmailMessageId

with foreign key on EmailMessage Id.

This does not work because when I tra to add a message I get an error that On EmailMessage Table is missing FromEmailMessageId or BccEmilMessageId field

So the question is I can I force builder to make distinct tables for Each list in EmailMessage class , without shadow properties ?

Thankyou for help

How can I Include condition with ICollection Return

$
0
0

Hi

I have the following model. I am trying to add  some additional select with depends on the condition  Please can you help in my code

 public class Event
    {
        public int EventId { get; set; }
        public string EventName { get; set; }
        public DateTime EventDate { get; set; }

        [ForeignKey("VenueId")]
        public int VenueId { get; set; }
        public Venue Venue { get; set; }
        public ICollection<Gig> Gigs { get; set; }
    }

public class Gig
    {
        public int GigId { get; set; }
        public string GigHeadline { get; set; }
        public int GigLengthInMinutes { get; set; }

        [ForeignKey("EventId")]
        public int EventId { get; set; }
        public Event Event { get; set; }

        [ForeignKey("ComedianId")]
        public int ComedianId { get; set; }
        public Comedian Comedian { get; set; }
    }

 public class Venue
    {
        public int VenueId { get; set; }
        public string VenueName { get; set; }
        public string Street { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string ZipCode { get; set; }
        public int Seating { get; set; }
        public bool ServesAlcohol { get; set; }
    }

  public class Comedian
    {
        public int ComedianId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string ContactPhone { get; set; }
    }

in dbContext
 public DbSet<Event> Events { get; set; }
 public DbSet<Comedian> Comedians { get; set; }
 public DbSet<Gig> Gigs { get; set; }
 public DbSet<Venue> Venues { get; set; }

I am trying to include statement with  conditionally in  the existing LinQ

 public ICollection<Event> GetEvents(bool includeGigs = false)
        {
            var _events = _db.Events.Include(v => v.Venue);
            // How can I add this condition with above _events 
          if (includeGigs)
            {
                _events = _events.Include(g => g.Gigs)
                             .ThenInclude(c => c.Comedian);
            }
// How can I add Order by condition with above _events 
            _events = _events.OrderBy(e => e.EventDate);
            return _events.ToList();
        }

existing php and mysql --- asp.net core CRUD required

$
0
0

dear all,

i have a php and mysql environment in Godaddy. I would like to create online applications - so that people can fill their form and submit their queries for admission. Maybe second line will be integrating to payment site etc.

I thought a simple approach will be to create asp.net core application and integrate with php mysql site.

any response will be helpful for me to go forward.

Warm Regards,

Sathya

Can't Run my app has IIS Express

$
0
0

Ok so I did some settings when trying to deploy asp.net core web app locally sometimes ago. Suddenly i just noticed that on vs when I try to run my app.

I can not run app with the IIS Express option. I have to pick the the name of the app when I want to debug.

https://pasteboard.co/J54l9V9.jpg   check that link for a snapshot so you understand what am saying

This is a snapshot of my vS to explain the problem.  Please this is a problem for me. Cos if I have multiple website on my solution I I cant run every thing at once.

How do I fix this problem. Got a problem with multiple sites and I need to run every thing at once so I can monitor all from IIS instance cos they all depend on each other to work well.

Bundle all Js file into one file

$
0
0

Hi Guys,

I am using ASP.NET MVC Core 3.1, I have below JS file how to bundle them into one file and link to Layout.cshtml 

<script src="~/lib/jquery-vectormap/worldmap.js"></script>
<script src="~/lib/jquery-vectormap/continents/asia.js"></script>
<script src="~/lib/jquery-vectormap/continents/africa.js"></script>
<script src="~/lib/jquery-vectormap/continents/europe.js"></script>
<script src="~/lib/jquery-vectormap/continents/northamerica.js"></script>
<script src="~/lib/jquery-vectormap/continents/oceania.js"></script>
<script src="~/lib/jquery-vectormap/continents/southamerica.js"></script>

Many Thanks,

Shabbir

Viewing all 9386 articles
Browse latest View live


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