Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.cshtml view not found #1252

Closed
thienedits opened this issue Feb 19, 2017 · 5 comments
Closed

.cshtml view not found #1252

thienedits opened this issue Feb 19, 2017 · 5 comments

Comments

@thienedits
Copy link

thienedits commented Feb 19, 2017

Environment data

dotnet --info output:

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

Product Information:
 Version:            1.0.0-preview2-003131
 Commit SHA-1 hash:  635cf40e58

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64

VS Code version: 1.9.1
C# Extension version: 1.7.0

Steps to reproduce

In the root folder I have a Controllers and Views folders. I am creating a simple view,

CategoriesController.cs:

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

namespace DiceWeb6.Controllers
{
    public class CategoriesController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Cat()
        {
            return View();
        }
        public IActionResult CategoriesCreator()
        {
            return View();
        }

  }
}

Views/Categories folder contains Cat.cshtml

Expected behavior

hitting http://localhost:58927/Categories/Cat should return the html file

Actual behavior

Getting a 404 error, page can't be found. If I create the code in Visual Studio and then open in vscode, the page renders. However anything I create in vscode does not return the html.

Request starting HTTP/1.1 GET http://localhost:58927/Categories/Cat  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:58927/Categories/Cat  
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 31.0532ms 404 
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Request","time":"2017-02-19T05:49:15.2043710Z","tags":{"ai.operation.id":"4LbqNEBn5fk=","ai.internal.sdkVersion":"aspnet5c:1.0.0","ai.operation.name":"GET /Categories/Cat","ai.device.roleInstance":"Eels","ai.user.userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"},"data":{"baseType":"RequestData","baseData":{"ver":2,"id":"4LbqNEBn5fk=","name":"GET /Categories/Cat","startTime":"2017-02-19T05:49:15.2043710+00:00","duration":"00:00:00.0208079","success":false,"responseCode":"404","url":"http://localhost:58927/Categories/Cat","httpMethod":"GET","properties":{"DeveloperMode":"true"}}}}
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 31.0532ms 404
@eByte23
Copy link

eByte23 commented Feb 20, 2017

@thienedits could you provide your project.json

seems like you need this part in it if you do not already

 "publishOptions": {
        "include": [
            "**/*.cshtml",
        ]
    }

@thienedits
Copy link
Author

Cool I added it and now it works. Thanks.

@thienedits
Copy link
Author

thienedits commented Apr 14, 2017

Hello I don't this is working. I thought it worked before because I readded a .cshtml file with the same that was deleted. When i create a new .cshtml its still the same error.

project.json

{
  "dependencies": {
    "EdCanHack.DiceNotation": "0.2.0",
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "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",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "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"
    }
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config",
      "**/*.cshtml"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

@gregg-miskelly
Copy link
Contributor

@thienedits this isn't a problem with the C# extension, and I don't know how many people here are experts on ASP.NET so you may have more luck asking your question in another repo.

That said, here are the differences that you might see when launching your app from VS Code vs. the command line:

  1. In earlier versions of the launch.json generator, we would default the current working directory to the workspace root instead of the project root. If you directory you are opening isn't the project directory, you could try changing that to see if it helps.
  2. We default to launch the web server in development mode (see env section of launch.json).

@JoeRobich
Copy link
Member

Closing as project.json is no longer supported. Please open a new issue if running into Razor issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants