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

Failed to open up Azure web app

$
0
0

I'm building MVC Core app using Visual Studio Code on Mac OS.

I created MVC app using yeo generator working with database EF core, everything works fine on localhost. I put correct connection string for my Azure SQL Server db in appsettings.json and ran app from Azure link but got error - "An error occurred while starting the application." without any details.

I checked my Azure by Kudu "http://<yoursitename>.scm.azurewebsites.net", the files are uploaded properly.
I also had a chance to check my Azure SQL using SQL Server Management Studio on Windows, my database is well published.

In my Azure, I got Web App Service, SQL sever(V12), SQL database under the same Resource name. All of their status are online and running.

I did quite a lot of research online for my problem but still got stuck for 2 days.... Please help!!!

What I did was:

1. dotnet ef migrations add InitialCreate -c ApplicationDbContext ==> Compilation succeeded.

2. dotnet ef database update -c ApplicationDbContext ==> Compilation succeeded.

3. dotnet run ==> Compilation succeeded.

Output of step 3:

info: Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory[1]
Executed DbCommand (373ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE') SELECT 1 ELSE SELECT 0

............... // doing DB seeding

info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
User profile is available. Using '/Users/matt/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Production
Content root path: /Users/matt/Documents/MyApp
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

4. git push -u azure master ==> Deployment successful.

Output of step 4:

............... // doing remote stuffs
remote: Finished successfully.
remote: Running post deployment command(s)...
remote: Deployment successful.
To https://myapp.scm.azurewebsites.net:443/myapp.git
85eecb5..914a2a0 master -> master
Branch master set up to track remote branch master from azure.

appsetting.json:

{"ConnectionStrings": {"DefaultConnection": "Server=tcp:myapp-test.database.windows.net,1433 ;Initial Catalog=myapp-test;Persist Security Info=False;User ID=<remove from blog>;Password=<remove from blog>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
   },"Logging": {"IncludeScopes": false,"LogLevel": {"Default": "Debug","System": "Information","Microsoft": "Information"
       }
   }
}

Configure method in Startup.cs:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationDbContext context)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();

    var configuration = new ConfigurationBuilder()
                            .AddEnvironmentVariables()
                            .AddJsonFile(env.ContentRootPath + "/config.json")
                            .Build();

    if (configuration.GetValue<bool>("EnableDeveloperExceptions"))
    {
        app.UseDeveloperExceptionPage();
        app.UseDatabaseErrorPage();
        app.UseBrowserLink();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
    }

    app.UseStaticFiles();

    app.UseIdentity();

    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });

    // Create database on startup
    using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
    {
        serviceScope.ServiceProvider.GetService<ApplicationDbContext>().Database.Migrate();
    }

    DbInitializer.Initializer(context);
}

web.config:

<?xml version="1.0" encoding="utf-8"?><configuration><system.webServer><handlers><add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/></handlers><aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/></system.webServer></configuration>

 


I follow the link https://www.asp.net/get-started but stuck when enable support for static files.

$
0
0

Sir,

While following the tutorial at Developer Command Prompt after enabling the support for static file my application does not build successfully .

When I add the code line "

app.UseStaticFiles();
" then this app does not compile.

How to add the UseStaticFiles package at Developer Command Prompt

Regards

Deployed asp.net core web site 404's on some pages which work locally

$
0
0

I have deployed to a IIS server and if I try to browse to a page that requires authorization then it redirects to the login page which is fine. However on POSTing the login page after filling in username and password it just 404's, even though that works fine locally.

Trying to browse to another page all together which doesnt require you to be logged in gives a 404, although it works fine when running in Visual Studio, its really stange.

In previous asp.net 4x applications I have done I had to add  <modules runAllManagedModulesForAllRequests="true">   to the web.config to get urls to work properly, if I try doing that on this asp net core app though I get a 500 error.

Error installing .NET Core SDK

$
0
0

I have an Error when trying to install Net Core.

Hi,

I already have Microsoft Visual C++ 2015 x64 (vc_redist.x64.exe) installed but when I try install .NET Core SDK 1.0.3 (dotnet-dev-win-x64.1.0.3.exe) it shows the following error:

Error 0x80070490: Failed to find expected public key in certificate chain.
Error 0x80070490: Failed to verify expected payload against actual certificate chain.
Error 0x80070490: Failed to verify signature of payload: VC_redist.x64.exe
Failed to verify payload: VC_redist.x64.exe at path: C:\ProgramData\Package Cache\.unverified\VC_redist.x64.exe, error: 0x80070490. Deleting file.
Error 0x80070490: Failed to cache payload: VC_redist.x64.exe

How I can fix it?.

How to: Add easy Azure MS SQL based Localization to VS 2017 Asp Net Core Web Application

$
0
0
Hi,

How can I easily add a Azure MSSQL Server based localization to my VS2017 Asp Net Core WebApp?
I want to add localized strings to Dataannotions, too.
Thanks
ERIC

Problem Complex Model

$
0
0

Already this week, I understand. Nothing happens. Configure authentication, it is impossible to make a comprehensive model.External Key (ForeignKey) added MySQL and the class is not initialized.
What is the problem?

[ComplexType]    public class ApplicationUser: IdentityUser {        public float Money {get; set; }        public string FinanceId {get; set; }        public virtual FinanceOperation Finance {get; set; }    }



FinanceId is, I've tested.But FinanceOperation not initialized.

[Table ( "financeoperations")]    public class FinanceOperation {        public string Id {get; set; }        public float Operation {get; set; }    }



Trying to appeal to this class:
this Controller: ManageController // Identity

[HttpGet]        public async Task <string> Index () {            string id = GetCurrentIdUser ();           // ApplicationUser user = _context.Users.FirstOrDefault (p => p.Id == id); // The user is, but Finance is not initialized.           . // ApplicationUser user = await _userManager.GetCureentUserAsync () Result; // The user is, but is not initialized Finance            if (user == null) return "User Error";            return user.Finance.Id.ToString (); // Here mistake that Finance is not initialized.        }



DbContext:

public class ApplicationDbContext: IdentityDbContext <ApplicationUser> {        public ApplicationDbContext (DbContextOptions <ApplicationDbContext> options): base (options) {}        protected override void OnModelCreating (ModelBuilder builder) {            base.OnModelCreating (builder);        }    }



As I have already tried everything?

Edit Blog

$
0
0

Hi. I am new to MVC Core. 

I have been attempting to get an edit blog working.

The code is at - https://github.com/DotNetDS/CoreMVC_Project.git

In the blog controller I have two edit methods.

I have commented the first one out so I can get to the blog page without an error and the edit does not work anyway.

On the blog page there is a html edit tag which I would like to take the site to an edit page.

Where the blog data can be edited. I have been struggling to find a tutorial to show me this exactly.

The error is (when uncommented).

An unhandled exception occurred while processing the request.

<div class="titleerror">AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

ExploreCalifornia.Controllers.BlogController.Index (ExploreCalifornia)
ExploreCalifornia.Controllers.BlogController.Edit (ExploreCalifornia)</div> <div class="titleerror"></div> <div class="titleerror">I am guessing its to do with routing. I would appreciate any help as I really want to see this working.</div>

Thanks,

Connecting to SQL using Domain IDs

$
0
0

I'm new to .NET Core (and .NET in general), and am struggling a bit with getting my web application to connect to an existing SQL server.

I've got rights to my SQL database, and I can get my web application to read/display data from the database (when running in Visual Studio 2017) when I'm logged into my Windows machine with my Active Directory domain account (that has rights on the database). But I'm trying to figure out how I can connect to the database using a separate/secondary domain user ID. Is this possible when using .NET Core?

I'm trying to tackle this because my web application will eventually communicate with a number of other databases. So I'm looking to use the same mechanism for all of them. And ideally I'm not looking to just set the application pool on the server to run with the ID, because I don't really want the same ID getting access to ALL the databases. Ideally I'm looking to separate out access rights to different IDs (sometimes the ID will have elevated access to certain databases).

Am I going to be able to connect to different databases using different domain IDs? Or should I just configure the application pool to run with a single ID and use that, or....?

Thanks!


Edit Blog, moving on or tryig to.

$
0
0

Hi. I am new to MVC Core. 
I have been attempting to get an edit blog working.
The code is at - https://github.com/DotNetDS/CoreMVC10052017a.git

If I type in http://localhost:50260/blog/edit/1,2,3 etc. It displays the correct record.

In Views/Blog/Index.cshtml line 30 I have <a asp-action="Edit" asp-route-id="@post.Id">Edit</a>.
Which is obviously wrong.

In Views/Blog/Edit.cshtml line 28 I have <button type="submit">Edit Post</button>.
Which is obviously doing nothing. i.e. does not update record.

Thanks,

Authorizing each controller/action

$
0
0

I'm putting together an intranet site for our company.  The administration wants complete control over everything. Basically, they want the ability to create "policy groups" at whim, and for each group, assign what they can do.  For example, View Users, Edit Users, Add New User.  What I've seen for .Core's authorization scheme, is that you can hardcode which group or users can use what controllers/actions.  However, since this is all dynamic, I don't want that.

I've been thinking about creating an custom attribute, that will contain an specific ID, for each action.  For example:

[HasPermission(1)]
public ActionResult ViewUsers(){}

[HasPermission(2)]
public ActionResult EditUsers(){}

And then in the database, I will assign 1=View Users, 2=Edit Users, etc... then they can assign groups to each record... simple database stuff.

So, if a user belongs to a group that has access to 1 and not 2, they will be limited to use ViewUsers and not EditUsers.

I want to know if this makes sense, or is there a better way of doing this.  Again, we're talking about a lot of controllers/actions that they want to assign users to, and create/manage/delete policy groups at their whim.

Thanks for any imput!

Updating database in .net core app after deploy

$
0
0

Hi everyone.
I have some problems with updating postgresql database after deploying my .net core application.
I deploying application to server throught octopus server and I have no idea how update my database after that.

I'll be glad to any help.

Where do I find ServerVariables("REMOTE_USER")?

Access HttpContext from class/model level validation method

$
0
0

So just to give some background I have changed my web application so it doesn't depend on accessing HttpContext.Current from class libraries, instead the entity framework context is passed around the application.

This is all working fine except for one small exception, in methods on models that are for class level validation I can't access HttpContext (as this is only available on controllers) and as the method is called automatically by the inner workdings of MVC I can't add a parameter to the method so i'm stuck.

public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
...
  });

How do I access the controller that has called the above function from within the function so I can access the HttpContext and then get the EF context so I can call a method in the business logic layer to check something, is the question? I have looked at the validationContext parameter but can't see a way of getting it from that.

Thanks

ASP.Net Core CRUD Operation

$
0
0

Hi All,

I wanna build multi layer application by using ASP.Net core(only windows only) and Entity Framework Core, perhaps am bit struck-up while accessing layered object.

Layer:

  • Business: Class library
  • Data: Class Library
  • Web: ASP.Net Core(Windows) 
  • Default Dependency Injection(AddScoped

I would be much appreciate if share any stuff to refer.

Thanks,

New to .Net Core - Web App - http client - apiclient

$
0
0

Hello,

I work in a big team and they want me to develop an extranet website and give access to couple tables from the SQL server... And make sure the rest is fully restricted...

They don't want to replicate the data to another server which involve lot security concerns.

They said to put no reference to the database at all in the website and that I have to develop a web app in the middle to handle the clients requests...

Our system is all in .Netcore for internal using a codefirst database...

I am not sure on where to start and how/what to use to do that.

Any code project or advice would be more than welcome...

I know how http client works basically but I am bit lost with .Net core...

I found this: and i dont know its its any help....

https://github.com/IEvangelist/Mirror/blob/master/Mirror/Networking/ApiClient.cs

please, someone, help!!


Recent annoucement dot net core 2.0

$
0
0

Apologies if I get this wrong but thought I read that we won't be able to do dot Net core with framework 4.6.1 with the next release.

I use dot net core with framework 4.6.1 to do my rest webapi services in front of  WCF by including the

client source from the WCF  (Generated with svcUtil.exe) into the webapi project.   Will this change in dot net core 2.0?

I fear 2.0 won't support this and will have to stop using dot net core as my rest webapi layer.

:( Oops. 500 Internal Server Error - An error occurred while starting the application.

$
0
0

I have created .net core web api application. When I start my .net core application I'm getting ":( Oops. 500 Internal Server Error - An error occurred while starting the application." error on the web page. Previously it's working fine but when I added "net462" instead of "netcoreapp1.0" into the project.json file it's occurred. Could you please let me know if anyone knows this issue?

Project.json

{"dependencies": {
    //"Microsoft.NETCore.App": {
    //  "version": "1.0.1",
    //  "type": "platform"
    //},"Microsoft.AspNetCore.Mvc": "1.0.1","Microsoft.AspNetCore.Routing": "1.0.1","Microsoft.AspNetCore.Server.IISIntegration": "1.0.0","Microsoft.AspNetCore.Server.Kestrel": "1.0.1","Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0","Microsoft.Extensions.Configuration.FileExtensions": "1.0.0","Microsoft.Extensions.Configuration.Json": "1.0.0","Microsoft.Extensions.Logging": "1.0.0","Microsoft.Extensions.Logging.Console": "1.0.0","Microsoft.Extensions.Logging.Debug": "1.0.0","Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0","IdentityModel": "2.0.0","Microsoft.AspNetCore.Diagnostics": "1.0.0","Microsoft.AspNetCore.Cors": "1.1.0","Newtonsoft.Json": "9.0.1","JsonWebTokens": "1.3.0","jose-jwt": "2.1.0","IdentityServer.DAL": "1.0.0-*","Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.1","System.IdentityModel.Tokens.Jwt": "5.1.3","Microsoft.IdentityModel.Protocols": "2.1.0","Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0","BouncyCastle.NetCore": "1.8.1.2","Sendgrid": "9.0.12","RollbarDotNet": "0.5.1","Microsoft.ApplicationInsights.AspNetCore": "1.0.2","IDAM.Sync": "1.0.0-*","Nse.ServiceBus.DataContracts": "1.8.0.350"
  },"tools": {"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },"frameworks": {"net462": {}
  },
  //"frameworks": {
  //  "netcoreapp1.0": {
  //    "imports": [
  //      "dotnet5.6",
  //      "portable-net45+win8"
  //    ]
  //  }
  //},"buildOptions": {"emitEntryPoint": true,"preserveCompilationContext": true
  },"runtimeOptions": {"configProperties": {"System.GC.Server": true
    }
  },"publishOptions": {"include": ["wwwroot","appsettings.json","web.config","nse.p12"
    ]
  },"scripts": {"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Child Window on a page in Core

$
0
0
Hi,
I need to learn how to incorporate a child window with scroll bars on an existing page in ASP Core. Suppose I have need to show some transactions of an account on the. Details view of an Account. But because of a lengthy list of the said transactions i need to show them in a child window built in on the same page.
What would be your suggestions, advice, reference for a sample piece of code (but for Core)
Thanks in advance.

Unable to resolve service for type ... while attempting to activate controller

Actually get Edit function to work

Viewing all 9386 articles
Browse latest View live


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