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

Change the EF Core connection string at runtime from a Controller

$
0
0

Hello,

I am using ASP.NET Core and EF Core for the creation of a Web API. I want to use thesame Web API (same controllers, same functionalities, etc.) formultiple databases. Therefore, what I want to accomplish is giving the connection string as a parameter to a controller and change it at runtime. For example, to use DB1 database, I want to make the following request:http://www.testserver.com/api/controller1/DB1 and change the connection string of the TestDbContext (which is TestDbContext : IdentityDbContext<TestUser>) as @"Server=(localdb)\MSSQLLocalDB;Database=DB1;integrated security=True;". If I want to use the DB2 then I'll make the same request but instead of DB1, I'll place the DB2 parameter. This is how I want my Web API finally to be working.

Is this possible? Can I change the EF Core connection string at runtime from a Controller? If yes, can anyone help me with this? If this is not possible, is there any other solution?

Please, I have tries a lot but I nothing seems to be working so I need your help.

Thanks in advance.


DI Framework

$
0
0

Hi,

I am using Unity as DI Framework. As I can seen it does not support .NET Core. What is the most widely used DI Framework for .NET Core?

Thanks

Published application size and structure: is it the final version?

$
0
0

I've been using ASP.NET for last 14 years(currently working with MVC 5)

Downloaded the new VS 2017 today and tried to create an empty ASP.NET Core webapplication. Then "Publish..."-ed it and didn't like what I got.

This is how the output directory looks like:

46 dll files in the root directory!

You can see a folder names "ref" there. This is  the contents of it:

83 dll files!!!

Overall output directory size is more than 6 mb. For empty project.

And this is an empty project with the minimum of packages.

I remember when it was "classic" ASP.NET and the published website had one dll in its "/bin" folder.

Then it was MVC's time and we had some more dll files but also in the "/bin".

I am sure we really need al these files. But isn't there any way to make it look better?

Visual Studio 2017 release .NET Core 1.1.1 Razor Tag Helpers do not get colorization

$
0
0

Hi,

My .csproj contains 

<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />

but Razor Tag Helpers do not get colorization nor intellisense.

Any help how to solve this problem please?

Thanks

Correct Publishing my Website

$
0
0

Hello,

i have some problems to publish my website. I have a asp.core website with angular 2 as frontent. Now i want to publish my website to my IIS. I publish with Web Deploy.

  • At Settings i can config some konfigurations (but i don't know what the different).
  • Target is .NETCoreApp,Version=v1.0
  • At Databases i see the connectionsstrings i write into my appsettings.json. i chose the "production" string and choose "use connection..."

First: But there is no setting to Exectute Code First Migration on Application Start. What can i do?

Second:  i used this code to get my connection string. i think this is not correct.

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("LocalConnection")));

Sorry for my bad english. 

splitting a form between partial views

$
0
0

I would like to have two partial views in which I can put the beginning form tag in one and the ending in another, so that I can place content between them:

@{await Html.RenderPartialAsync("../PartialFormBegin").ConfigureAwait(false);}
@{await Html.RenderPartialAsync("_ContentCreateEdit").ConfigureAwait(false); }
@{await Html.RenderPartialAsync("../PartialFormEnd").ConfigureAwait(false); }

The following is code for the form begin and end partial views:

<form asp-area=@ViewBag.Area asp-controller=@ViewBag.Controller asp-action=@ViewBag.Action asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal"><hr /><div asp-validation-summary="All" class="text-danger"></div><div class="form-group"><div class="col-md-offset-3 required form-inline"><span style="font-weight:bold;">Required field</span></div></div><div class="form-group"><div class="col-md-offset-4"><button type="submit" class="btn btn-default col-md-offset-1" tabindex="6">Save</button></div></div></form>

When I attempt to do this, however, it produces this error: Found a malformed 'form' tag helper. Tag helpers must have a start and end tag or be self closing.

 Is there any other way to approach this, or do I just have to repeat the whole form each time? I'd rather be "DRY" and have it all in one partial view in case of errors, changes, etc. It would be nice if it finished reading all partial views contained therein before jumping to conclusions. I'm quite sure I was able to do something in previous WebForms versions, but surely not in this version of .Net Core MVC.

"DRY" form tag uniformity in one component or partial view

$
0
0

I have a number of form tags that look similar:

<form asp-area=@ViewBag.Area asp-controller=@ViewBag.Controller asp-action=@ViewBag.Action asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">

It would be nice if I put everything in "<form ... >" into a "super ViewBag" or partial view so I have it all in one place in case of changes. I've unsuccessfully tried a number of ways. Any ideas?

Login Name without the Domain name showing (No Java Script)

$
0
0

 I need to display the current logged in user name.  I have the login name control but it is displaying the domaniname\username.

How do I display the username only? ( I know how to do using java script but I do not want that )


when i type dotnet new in console , it's not create a new project , the console display other things like examples..

$
0
0

i cant create new console application from command line when i type dotnet new , i got this output as seen in this image 


F:\Projects\ASP Core Projects\tutorial\HelloWorld>dotnet new
Template Instantiation Commands for .NET Core CLI.

Usage: dotnet new [arguments] [options]

Arguments:
template The template to instantiate.

Options:
-l|--list List templates containing the specified name.
-lang|--language Specifies the language of the template to create
-n|--name The name for the output being created. If no name is specified, the name of the current directory is used.
-o|--output Location to place the generated output.
-h|--help Displays help for this command.
-all|--show-all Shows all templates


Templates Short Name Language Tags
--------------------------------------------------------------------------------------
Console Application console [C#], F# Common/Console
Class library classlib [C#], F# Common/Library
Unit Test Project mstest [C#], F# Test/MSTest
xUnit Test Project xunit [C#], F# Test/xUnit
Empty ASP.NET Core Web Application web [C#] Web/Empty
MVC ASP.NET Core Web Application mvc [C#], F# Web/MVC
Web API ASP.NET Core Web Application webapi [C#] Web/WebAPI
Solution File sln Solution

Examples:
dotnet new mvc --auth None --framework netcoreapp1.0
dotnet new web --framework netcoreapp1.0
dotnet new --help

F:\Projects\ASP Core Projects\tutorial\HelloWorld>

google claim based authentication

$
0
0

Hi guys,

I want to know google claim based authentication.(For Example : Full User Name / Country Code / Profile Image URL...and etc..)

Does guys have demo code or related blog article?

Using an unspecified model in a partial view

$
0
0
Hello
I want to to send an unspecified model with another model that includes the information of parameters of the first model into a partial view and build the input parameters.
The second model includes the name in database and caption and type (alphabetic or numeric or list,...) and some other information about parameters for example items of list type in xml format and etc.
The problem is I don't have the exact name of first model properties and is identified by second one.
How can I build my enterance form and save the data in the related table.

How to develop core and non-core based apps using VS2015 and VS2017

$
0
0

when we develop application using VS2015 / VS2017 then does it means that my application will be develop on dotnet core and i can run on any platform like linux, windows and mac etc ?

how to develop non core apps with VS2015 / VS2017 which will run only on windows OS not linux/ MAC.

what option is there in those IDE which make my apps core or non core ?

please guide me. thanks

How to import file csv in Sql Server with ASP.NET Core 1.1 MVC ...

$
0
0

Hello everyone, I am developing with ASP.NET MVC 1.1 Core and I need to import csv files into SQL Server,
it would seem that ADO.NET can not use more or better data structures like "DataTable" and "DataRow" no longer seem 
recognized even if I included the "libraries using System.Data;", "Using System.Data.Common;" and "using System.Data.SqlClient;".If you confirmed me thatI canno longer useAdo.Net(ieDatatableandDataRow) direct mehow to developthe importofcsvinSqlServer?

adding package in linux

$
0
0

Hi,

Because of several problems with VS 2017 Bugs and it's enormous wight (like other Visual Studios) I decided to code in linux by VS Code and I managed almost.however say that I want to use a function ,like ServerFile(),whose package is not included at first (Microsoft.AspNetCore.StaticFiles ),how should I install that package in linux ?  

Authenticating / Authorizing to grant external website access to an asp.net core mvc application.

$
0
0

Hello all,

We have developed a ASP.NET MVC CORE 1.1 application with default authentication scheme. We are also using claims based structure for profile differentiation to allow / prevent access to some information on some views. Now some of the views will be showed on a outside website based on joomla / php that has to authenticate to allow POST and GET actions on some controllers.

I have not been able authenticate from the joomla php website using basic HTTP authorization first with a header containing a valid user a pass base64 encoded. I also tried to extract the token authentication cookie and the request verification hidden field token to post on the /Account/Login form with valid information to get legitimate access to our application. I've lost too much time with this and i am looking for solution to get legitimate access to the application from outside. We are using Kestrel as a webserver. Can you please advise and present an example on how to do this?

Thanks in advance


502.3 Bad Gateway - Web API and MVC on same IIS Server with Integrated Windows Authentication

$
0
0

I've been trying to solve this issue for several days now, but I haven't found anyone able to help. Kind of reaching out here hoping to reach someone who knows where I'm going wrong.

I have an ASP.NET Core MVC application with a Web API as well (1.1) that uses Integrated Windows Authentication (NTLM), and WindowsIdentity Class impersonation to forward user credentials from MVC to the API for REST calls. 

What is happening is I am getting a "502.3 Bad Gateway" whenever I do a try and redirect the user in an Action method on the MVC application after issuing a POST/PUT request to the Web API. I want to clarify that the request is generated in the MVC application, and the actual request goes through the API, and the response does come back to the MVC application. The URL would be generated that a redirect should be sent to, but the 502.3 happens right at this point. It doesn't matter if I'm on IIS Express, Testing Server IIS, or Production Server IIS, they all net the same result. This started happening after I added in the Impersonation portion of my program. I don't know if this is an IIS issue or a .NET Core issue.

The steps are as follows:
1. User hits submit or save (Creating a new or saving an old one)
2. User credentials are impersonated with WindowsIdentity.RunImpersonated() and a REST call is made 
3. The POST/PUT request is sent to the Web API, and a 200 response is received
4. Based upon that Status Code (200/201/204) I have RedirectToAction() setup to send them to the view of the updated/created object
5. The HTTP GET request is sent for the View of that object
6. 502 Error is thrown

Here's what the log files look like:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 POST http://<server>/tim/Incidents/SaveIncident?incidentId=58 application/x-www-form-urlencoded 763
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1]
      Authorization was successful for user: [user].
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method TIM.MVC.Controllers.IncidentsController.SaveIncident (TIM.MVC) with arguments (58, TIM.API.Models.Incident) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.RedirectResultExecutor[1]
      Executing RedirectResult, redirecting to /tim/Incidents/View/58.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action TIM.MVC.Controllers.IncidentsController.SaveIncident (TIM.MVC) in 1397.8175ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 2097.562ms 302
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://<server>/tim/Incidents/View/58
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[1]
      Authorization was successful for user: [user].
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method TIM.MVC.Controllers.IncidentsController.View (TIM.MVC) with arguments (58) - ModelState is Valid



I've gone through every Stackoverflow thread (and created a couple of my own), and even tried using the ASP.NET Github issues to find a resolution. Anything I try has no effect on the outcome. I'm hoping someone can give me some advice as to what to look for.

Things I have tried:
* Doing just Redirect() to the URL that should be generated
* Adding a Database and AspNetModule Timeout
* Giving the Application Pool full access to every single folder on IIS

Receive Invalid Token From Twitter on Azure but locahost is ok

$
0
0

Hi,

I'm using Linq2Twitter plugin to link my site to Twitter, users are able to authenticate on localhost but once deployed to Azure, Twitter most likely provides invalid tokens....

I have described the problem here: http://stackoverflow.com/questions/42708752/linq2twitter-callback-working-on-localhost-but-not-azure

But after investigation I can see that the callback url is identical (the hostname is different indeed due to localhost/live site) but Twitter API would provide different token/verifier.

I have my live site url set as https://sarahah.com as  the website in dev.twitter.com

Thank you

Runtime error after adding Microsoft.AspNetCore.Session and Microsoft.Extensions.Caching.Memory

$
0
0

All I ever wanted was to use TempData in my application Cry

So long story short, my project.json dependencies now looks like this:

"dependencies": {"Microsoft.ApplicationInsights.AspNetCore": "1.0.0","Microsoft.AspNetCore.Authentication.Cookies": "1.0.0","Microsoft.AspNetCore.Diagnostics": "1.0.0","Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0","Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0","Microsoft.AspNetCore.Mvc": "1.0.1","Microsoft.AspNetCore.Razor.Tools": {"version": "1.0.0-preview2-final","type": "build"
    },"Microsoft.AspNetCore.Routing": "1.0.1","Microsoft.AspNetCore.Server.IISIntegration": "1.0.0","Microsoft.AspNetCore.Server.Kestrel": "1.0.1","Microsoft.AspNetCore.Session": "1.0.0-rc2-final","Microsoft.AspNetCore.StaticFiles": "1.0.0","Microsoft.EntityFrameworkCore.SqlServer": "1.0.1","Microsoft.EntityFrameworkCore.SqlServer.Design": {"version": "1.0.1","type": "build"
    },"Microsoft.EntityFrameworkCore.Tools": {"version": "1.1.0","type": "build"
    },"Microsoft.Extensions.Caching.Memory": "1.1.1","Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0","Microsoft.Extensions.Configuration.Json": "1.0.0","Microsoft.Extensions.Configuration.UserSecrets": "1.0.0","Microsoft.Extensions.Logging": "1.1.1","Microsoft.Extensions.Logging.Console": "1.0.0","Microsoft.Extensions.Logging.Debug": "1.0.0","Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0","Microsoft.NETCore.App": {"version": "1.0.1","type": "platform"
    },"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0","Microsoft.VisualStudio.Web.CodeGeneration.Tools": {"version": "1.0.0-preview2-final","type": "build"
    },"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {"version": "1.0.0-preview2-final","type": "build"
    }
  },

Now my project compiles, but I get a runtime error, which appears to have issue with services.AddSession() in my ConfigureServices (Startup.cs). Any ideas?

error message:

Message=Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Generic Web handler ashx in .net core

$
0
0

   Hi in mvc5 i have a NotificationHandler.ashx  handler and i make something 

if (context.Request.HttpMethod == "POST") { i get a json context and do something.... }
and the url is https://mysite/HttpHandler/NotificationHandler.ashx

h
ow do i make exactly the same in a Middleware handler in .net core ? My proble is the url in mvc5 i made ashx (it is url) in .net core how can
do that ?

    public class NotificationHandler    {        private readonly RequestDelegate _next;public NotificationHandler(RequestDelegate next)        {            _next = next;        }        public async Task Invoke(HttpContext httpContext)        {        if (httpContext.Request.Method == "POST"){   //do something.....i get json here        }                return _next(httpContext);
	}    }    // Extension method used to add the middleware to the HTTP request pipeline.    public static class NotificationHandlerExtensions    {        public static IApplicationBuilder UseNotificationHandler(this IApplicationBuilder builder)        {            return builder.UseMiddleware<NotificationHandler>();        }    }
I am confused because i need a url to send me cloud services json

Project Hierarchy, What Technologies to use?

$
0
0

Hi,

I want to write application separated to 3 parts. Client Service, Service, Web.

Let's say we have for example 5 computers and 1 server. Each computer will run Client Service. Server will run Service and Web.
I thinking of Client Service as Windows Service Project. Service as WCF Service and Web as ASP.NET Core (.NET Framework).

Client Service will collect data about users and send it to WCF Service to write it to db.
Web will work as data viewer with graphs etc.

So what's the question?
Currently thinking of if its possible for WCF to connect to ASP.NET Core or is there a better solution instead of WCF? I think WebAPI is not great solution for this.
Also do you think its better to design for each database table own manager for add/edit/delete etc. or share through WCF DatabaseContext to Web for display or make own DatabaseContext for Web? Or Just share from WCF ConnectionString?

I don't have much experience in designing in this concept. So better to ask someone who's experienced :)

Thanks.

Viewing all 9386 articles
Browse latest View live


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