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

Linux + nginx + subfolder

$
0
0

Hi,

The new version of our platform wEngine is using asp.net core 1.0 and  works under Linux (Debian Jessie + nginx).

We are now working to have our platform be install-able in a subfolder, for example: 

URL: domain.com/applicationname

NGINX Configuration: location /applicationname

What we want to achieve

  • We want to install multiple applications under the same domain (domain.com)
  • We want the url's to be like:  domain.com/app1, domain.com/app2
  • We want to be able to use the same port for all applications

Our Problem

We can configure nginx for serving domain.com/app1 and forwarding to the asp.net applicationapp1 
but asp.net routing gets confused with a subfolder in the url.  It will get different routes depending on url:

  • domain.com
  • domain.com/app1

One solution may be to programmatically create routes like:

var appname="app1/";  //From configuration, Develop/Staging/Production
var route=appname+"{controller=home}/{action=index}/{id?}"
But I don't know if its a good solution.

What is the recommended best practice in this scenario with Linux and nginx?

Thanks! Best Regards

weboholics.se


ASP.Net Core and MySql

$
0
0

Tell me how to use ASP.Net Core and MySql? It is advisable to use Dapper

asp.net core AntiXSS

$
0
0

Hi guys,

how to do a anti xss in asp.net core ? 

AntiXSS not support for asp.net core 1.0.

any idea?

Regards

Yam

Error in case of up-dating of packets Nuget.

$
0
0

Hi!

PATH=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe restore "C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\.vs\restore.dg"
log  : Restoring packages for C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\project.json...
log  : Restoring packages for tool 'Microsoft.AspNetCore.Razor.Tools' in C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\project.json...
log  : Restoring packages for tool 'Microsoft.AspNetCore.Server.IISIntegration.Tools' in C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\project.json...
log  : Restoring packages for tool 'Microsoft.EntityFrameworkCore.Tools' in C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\project.json...
log  : Restoring packages for tool 'Microsoft.Extensions.SecretManager.Tools' in C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\project.json...
log  : Restoring packages for tool 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' in C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\project.json...
error: Version conflict detected for Microsoft.CodeAnalysis.Common. 
error:  ProjectX (>= 1.0.0) -> Microsoft.AspNetCore.Mvc (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.Razor (>= 1.0.0) -> Microsoft.CodeAnalysis.CSharp (>= 1.3.0) -> Microsoft.CodeAnalysis.Common (= 1.3.0) 
error:  ProjectX (>= 1.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Tools (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.Core (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.Templating (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.Utils (>= 1.0.0-preview1-final) -> Microsoft.CodeAnalysis.CSharp.Workspaces (>= 1.3.0-beta1-20160429-01) -> Microsoft.CodeAnalysis.Workspaces.Common (= 1.3.0-beta1-20160429-01) -> Microsoft.CodeAnalysis.Common (= 1.3.0-beta1-20160429-01).
log  : Writing lock file to disk. Path: C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\project.lock.json
log  : C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\ProjectX.xproj
log  : Restore failed in 13039ms.
Errors in C:\Users\dbaev\Documents\Visual Studio 2015\Projects\ASP.NET Core\ProjectX\src\ProjectX\ProjectX.xproj
    Version conflict detected for Microsoft.CodeAnalysis.Common.
     ProjectX (>= 1.0.0) -> Microsoft.AspNetCore.Mvc (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.Razor (>= 1.0.0) -> Microsoft.CodeAnalysis.CSharp (>= 1.3.0) -> Microsoft.CodeAnalysis.Common (= 1.3.0)
     ProjectX (>= 1.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Tools (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.Core (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.Templating (>= 1.0.0-preview1-final) -> Microsoft.VisualStudio.Web.CodeGeneration.Utils (>= 1.0.0-preview1-final) -> Microsoft.CodeAnalysis.CSharp.Workspaces (>= 1.3.0-beta1-20160429-01) -> Microsoft.CodeAnalysis.Workspaces.Common (= 1.3.0-beta1-20160429-01) -> Microsoft.CodeAnalysis.Common (= 1.3.0-beta1-20160429-01).

How to correct it?

Thanks you!

Call WCF Service in ASP.NET Core

$
0
0

We are starting a new application and I have been kicking the tires on ASP.NET 5 trying to get used to all of the new features. So far everything looks really good, but I have encountered a road block that I cannot seem to get beyond. I never dreamed this would be that difficult. The web application we are going to develop is new but most of the back end services are not. They are old SOAP services created with WCF. As everyone knows, in the past this was as simple as having the url to the service and clicking "Add Service Reference" and you're done. I am not really surprised that this has changed, but I didn't think support for this situation wouldn't be there. In any case, I cannot seem to figure this out.

I have seen a few old posts about this subject, but none of them have helped. I also saw a promising tool called "WCF Connected Service Visual Studio Extension Preview for ASP.NET 5 Projects", but it wouldn't install for me in Visual Studio 2015 Update 3. Ultimately, our app will be hosted in IIS and have access to the full .net framework if that makes a difference. It would be a shame if I couldn't use these great new features because this is either not possible or too time consuming to implement by hand. 

TIA, Greg

Upload Images after preview with generic handler

$
0
0

Hi every body :)

I create a image uploader with jquery and ASP generic handler!

when images select or drop,upload automatically start!

is there any way to start upload after click?

I mean at first user drop or select images(maybe remove some of them after preview) and finally click upload!

Thanks a lot!

aspx code:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"><script src="latestJs_1.11/jquery.min.js"></script><script src="DropzoneJs_scripts/dropzone.js"></script><link href="DropzoneJs_scripts/dropzone.css" rel="stylesheet" /></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><h4>Upload image using DropzoneJS in Asp.net C#.</h4><a title="For details Explanation click here" target="_blank" href="http://codepedia.info/2015/03/using-dropzone-js-file-image-upload-in-asp-net-webform-c/?github=tuts#">Click here for explaination</a><br /><br /><div id="dZUpload" class="dropzone"><div class="dz-default dz-message">
            Drop image here. </div></div><script type="text/javascript">$(document).ready(function () {
            console.log("Hello");
            Dropzone.autoDiscover = false;
            //Simple Dropzonejs $("#dZUpload").dropzone({
                maxFiles: 5,
                addRemoveLinks: true,
                success: function (file, response) {
                    var imgName = response;
                    file.previewElement.classList.add("dz-success");
                    console.log("Successfully uploaded :" + imgName);
                },
                error: function (file, response) {
                    file.previewElement.classList.add("dz-error");
                }
            });
        });</script><asp:Button ID="btnUpload" runat="server" Text="Upload" /></asp:Content>

handler code:

 public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string dirFullPath = HttpContext.Current.Server.MapPath("~/MediaUploader/");
            string[] files;
            int numFiles;
            files = System.IO.Directory.GetFiles(dirFullPath);
            numFiles = files.Length;
            numFiles = numFiles + 1;

            string str_image = "";

            foreach (string s in context.Request.Files)
            {
                HttpPostedFile file = context.Request.Files[s];
                string fileName = file.FileName;
                string fileExtension = file.ContentType;

                if (!string.IsNullOrEmpty(fileName))
                {
                    fileExtension = Path.GetExtension(fileName);
                    str_image = "MyPHOTO_" + numFiles.ToString() + fileExtension;
                    string pathToSave = HttpContext.Current.Server.MapPath("~/MediaUploader/") + str_image;
                    file.SaveAs(pathToSave);
                }
            }
            context.Response.Write(str_image);
        }

database created in SQL Server 2008 - can we use in Asp.net project in Visual Studio 2015

$
0
0

Dear all,

I have created and used a database for my asp.net application in SQL Server 2008. Now I would like to use that database in Visual Studio 2015 - in my local system for testing and development.

I am not getting the import option in visual studio 2015 application for this.

Can anyone suggest a way to use this in my Visual Studio 2015 application.

Cheers

Sathya

List of checkboxes

$
0
0

Hi,

In my database I have Offers, Levels(basic, intermediate, expert) and OfferLevels tables. One offer can have zero or multiple Levels.

I can create website which will create new offer but I cant figure out how to write levels to OfferLevels table.

I want to display levels as 3 checkboxes.

Could somebody help me with how to write controller, viewmodel(hold offer and levels objects) and view with asp.net core?

My code:

Controller
        public IActionResult Create()
        {
            var viewModel = new ViewModel();
            return View(viewModel);
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public IActionResult Create(ViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.Offer.OfferDate = DateTime.Now.ToLocalTime();
                context.Offers.Add(viewModel.Offer);
                context.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(viewModel.Offer);
        }

ViewModel
    public partial class ViewModel
    {
        public Offer Offer { get; set; }
        public List<Level> Levels { get; set; }
    }

View
<form asp-controller="Home" asp-action="Create" method="post" class="form-horizontal" role="form"><div asp-validation-summary="All" class="text-danger"></div><div class="form-group"><label asp-for="Offer.OfferTitle"></label><input asp-for="Offer.OfferTitle" class="form-control" /><span asp-validation-for="Offer.OfferTitle" class="text-danger"></span></div>

....there should be checboxes dont how to put them here....

    <div class="form-group"><input type="submit" value="Create" class="btn btn-default" /></div></form>


ASP.NET Core Azure Webjobs

$
0
0

Hi there. 

I was wondering if anyone has had any experience creating/migrating Azure web-jobs on ASP.NET Core. I can't find any resources that really address it. I know there's a few workarounds but they seem a bit creaky. 

Any help would be much appreciated. 

Cheers,

Josh. 

dotnet publish error. web.config is not getting updated

$
0
0

Hi,
I have an issue when publishing a new ASP.NET Core 1.0 application on a build server. The build completes successfully, but web.config is not getting updated.

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Publishing.targets(149,5): Error : Could not load file or assembly 'Microsoft.DotNet.ProjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.ProjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.DotNet.ProjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at Microsoft.AspNetCore.Server.IISIntegration.Tools.PublishIISCommand.Run()
   at Microsoft.AspNetCore.Server.IISIntegration.Tools.Program.<>c__DisplayClass0_0.<Main>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.AspNetCore.Server.IISIntegration.Tools.Program.Main(String[] args)
-----------------------------------------------

.NET Command Line Tools (1.0.0-preview2-003121)

Product Information:
 Version:            1.0.0-preview2-003121
 Commit SHA-1 hash:  1e9d529bc5

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.3.9600
 OS Platform: Windows
 RID:         win81-x64

-----------------------------------------------

Captcha in asp.net core

$
0
0
How can I add CAPTCHA in asp.net core 1.0 application?

is the below namespace available in asp.net core 1.0 preview 2.

$
0
0

Hi There, 

Am migrating my existing project to asp.net core 1.0. in that following API's are not available in latest version. i have surfed a lot in net. but could not find it. 

Could any one have a look on below API whether available in latest .net core 1.0 preview 2. if so, in which namespace it is avail. 

  

API / Class 

Namespace available in Existing project

RNGCryptoServiceProvider

System.Security.Cryptography

Encoding

System.text

PasswordDeriveBytes

System.security.cryptography

Rijndael

System.security.cryptography

imaging

System.drawing

Image

System.drawing

SpeechSynthesizer

System.speech.synthesis

PermissionSet

System.Security.Permissions

if the above is not avail in latest, is there any plan to include it in upcoming releases ? 

-Gurunathan 

Entity Framework core installation within Service Fabric Core Web API

$
0
0

Hello,

I'm using the Service Fabric core solution template with Visual Studio 2015 update 3 and created a stateless web api.

Within this project, I would like to use Entity Framework core.

When trying to install the nuget package using:  Install-Package Microsoft.EntityFrameworkCore.SqlServer

I get the following error:

Install failed. Rolling back...
Package 'Microsoft.EntityFrameworkCore.SqlServer.1.0.0' does not exist in project 'License_Services'
Package 'Microsoft.EntityFrameworkCore.SqlServer.1.0.0' does not exist in folder 'C:\GitHub\eco-csp-portal\eco-csp-portal\packages'
Install-Package : Could not install package 'Microsoft.EntityFrameworkCore.SqlServer 1.0.0'. You are trying to install this package into a project that targets'Unsupported,Version=v0.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact
the package author.
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore.SqlServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Does this have to do with the fact that the service fabric core template is for RC2 and not 1.0?

Will there be an update soon?

Thanks

Martin

Process manager for Linux web hosting

$
0
0

Now that ASP.NET Core is available for Linux, I'd like to use it on my web server. It's running Ubuntu 14.04 (upgrade to 16.04 scheduled for autumn) and Apache with a multi-user shared web hosting configuration. Each user has their own system user account and owns all their files. PHP is already set up with suEXEC. This roughly corresponds to the application pool identity in IIS/Windows.

The official Linux setup guide describes how to configure the reverse proxy with Nginx and use supervisor as process manager. I haven't heard of supervisor before and feel like it has some flaws that cause trouble with hosting processes. I like the idea of AspNetCore module for IIS but that isn't available for Apache and probably won't anytime soon. So I'm looking into creating my own solution for that.

I know how to configure the reverse proxy in Apache and in fact I have my custom script in place that generates the VirtualHost configurations for all domains based on a database backend. This could also generate the proxy configuration. My idea is to write a program that does the process management, reading from the same database backend:

  • Runs as daemon with root privilege, started with the system, never restarted for configuration
  • Reads the database to know which web applications to start on which TCP port
  • Re-reads the database regularly for updated configuration
  • Starts the web application process under the user that owns the files (prevent starting as root)
  • Reads the published web.config file to know the start command, logging and restart options etc.
  • Monitors started child processes and performs restarting according to configuration in web.config

Because it would be able to read the web.config file, the only database contents is the public URL, the local port, and the application base directory.

I'm looking into writing this as a .NET Core application itself so it doesn't have additional runtime requirements. Hopefully this provides all the security and process APIs I need.

Does something like this already exist? Is anybody interested in such a solution? Any further ideas, concerns, or tips?

I guess that the public URL as well as the local port are specified by the calling process through environment variables. I haven't looked closely at how AspNetCore module does it yet.

IIS Hosting

$
0
0

I am trying to host my test site on IIS. The article in the docs seems to be out of date. There are packages that are referred to (Microsoft.AspNetCore.Server.IISIntegration) that either don't exist or have been renamed. Others fail to install because they don't target the version of the framework I am using which is "net461" only. For what it's worth, I am running IIS on Windows 7.

Thanks,

Greg


Unable to deploy ASP.NET core docker image

$
0
0

Hi All,

I'm trying to build Docker image using the ASP.NET core 1.0. I'm windows 10 x64 bit. I have the following installed

1) Docker for Windows

2) Docker tools for VS 2015

After I create a ASP.NET core 1.0 app, I added the docker support. Then from powershell I executed the following commands.\DockerTask.ps1-Build-EnvironmentRelease

Then when I try to run the Docker image using the command \DockerTask.ps1 -run-EnvironmentRelease

I get the below error

Creating network "dockerapp_default" with the default driver Creating dockerapp_dockerapp_1

ERROR: for dockerapp  driver failed programming external connectivity on endpoint dockerapp_dockerapp_1 (55ca50e4579c408 c8f3a7d289c55de67b0089c1f9f835c77416dbff1ac4427b1): Error starting userland proxy: write /port/tcp:0.0.0.0:80:tcp:172.18 .0.2:80/ctl: errno 526 ERROR: Encountered errors while bringing up the project. Run : Failed to start the container(s) At D:\Venkatesh\ASPNETCore\DockerDeployement\DefaultApp\DockerApp\src\DockerApp\DockerTask.ps1:507 char:5 +     Run +     ~~~     + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException     + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Run

Upload and Resize multiple Image

$
0
0

Hi :)

I'm trying to upload multiple images and resize them before upload!

I use this code But it's resize and save just the firs selected image!

for example if 2 image selected , the first one resize and upload twice!

thanks for any Help!

protected void uploadFile_Click(object sender, EventArgs e)
        {                
                // Check file exist or not  
                if (UploadImages.PostedFile != null)
                {
                    // Check the extension of image  
                    string extension = Path.GetExtension(UploadImages.FileName);
                    if (extension.ToLower() == ".png" || extension.ToLower() == ".jpg")
                    {
                        int name = 101101;
                        int count = 1;
                        foreach (HttpPostedFile postedfile in UploadImages.PostedFiles)
                        {
                            Stream strm = UploadImages.PostedFile.InputStream;
                            var image = System.Drawing.Image.FromStream(strm);
                            string imgName = Convert.ToString(name) + "_" + Convert.ToString(count);
                            // Print Original Size of file (Height or Width)   
                            Label1.Text = image.Size.ToString();
                            int newWidth = image.Width / 2; // New Width of Image in Pixel  
                            int newHeight = image.Height / 2; // New Height of Image in Pixel  
                            var thumbImg = new Bitmap(newWidth, newHeight);
                            var thumbGraph = Graphics.FromImage(thumbImg);
                            thumbGraph.CompositingQuality = CompositingQuality.HighSpeed;
                            thumbGraph.SmoothingMode = SmoothingMode.HighSpeed;
                            thumbGraph.InterpolationMode = InterpolationMode.Low;
                            var imgRectangle = new Rectangle(0, 0, newWidth, newHeight);
                            thumbGraph.DrawImage(image, imgRectangle);
                            // Save the file  
                            string targetPath = Server.MapPath(@"~\Images\") + imgName + ".jpg";
                            thumbImg.Save(targetPath, image.RawFormat);   
                            count++; 
                        }
                    }
                }
            } 

 

ASP.Net Core Session Enablement

$
0
0

Hi,

I am trying to develop an application that can use session management, I had included following two dependencies in project.json as per core documentation:

"Microsoft.AspNetCore.Session": "1.0.0","Microsoft.Extensions.Caching.Memory": "1.0.0",

But now when i compile the solution there is an error in program.cs at UseContentRoot function that 

Severity Code Description Project File Line Suppression State
Error CS0121 The call is ambiguous between the following methods or properties: 'Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.UseContentRoot(Microsoft.AspNetCore.Hosting.IWebHostBuilder, string)' and 'Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions.UseContentRoot(Microsoft.AspNetCore.Hosting.IWebHostBuilder, string)' WebApplication1..NETCoreApp,Version=v1.0 C:\Testing\WebApplication1\src\WebApplication1\Program.cs 16 Active

Sample project is uploaded at dropbox https://www.dropbox.com/s/1l5clva6c9gdnwe/WebApplication1.rar?dl=0

Please help me get out of this issue !

Asp.Net Core (.Net Core) vs Asp.Net Core (.Net Framework)

$
0
0

When developing Asp.Net Core Web Apps there are 2 options to choose, 2 frameworks to choose which to use; .Net Core and .Net Framework. Can someone explain me a bit what are the differences between those two, even while both cover Asp.Net Core Web Apps? I develop with Visual Studio 2015.

.net core 1.0 for Ubuntu Linux install

Viewing all 9386 articles
Browse latest View live


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