Click here to Skip to main content
15,888,521 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Loop through dataset to create hyperlinks in aspx Pin
Richard Deeming4-Jul-18 7:37
mveRichard Deeming4-Jul-18 7:37 
PraiseRe: Loop through dataset to create hyperlinks in aspx Pin
caffrey_14-Jul-18 10:27
caffrey_14-Jul-18 10:27 
QuestionBinding selected value of Dropdownlist to Grid Pin
indian1433-Jul-18 12:58
indian1433-Jul-18 12:58 
AnswerRe: Binding selected value of Dropdownlist to Grid Pin
Vincent Maverick Durano3-Jul-18 16:20
professionalVincent Maverick Durano3-Jul-18 16:20 
Question.Net Core 2.1 IHostingEnvironment, how to access it Pin
jkirkerx28-Jun-18 20:14
professionaljkirkerx28-Jun-18 20:14 
AnswerRe: .Net Core 2.1 IHostingEnvironment, how to access it Pin
Richard Deeming29-Jun-18 0:00
mveRichard Deeming29-Jun-18 0:00 
GeneralRe: .Net Core 2.1 IHostingEnvironment, how to access it Pin
jkirkerx29-Jun-18 6:18
professionaljkirkerx29-Jun-18 6:18 
Question.Net Core 2.1, Get the Environment to seed a database so I can get the path Pin
jkirkerx28-Jun-18 9:02
professionaljkirkerx28-Jun-18 9:02 
I have 2 issues here on replacing MapPath. After reading many articles on the subject, guess I am the sloppy programmer that used MapPath inside functions to handle physical file locations for image and html file reading and writing.

On the first issue, I seeded my database with data that includes blobs of image bytes and then wrote the bytes to the folder as an image. I'm seeding my database in Program.cs which works fine, it creates the database but I can't grasp the MapPath or Environment.
I noticed in CreateWebHostBulder, if I add .ConfigureAppConfiguration((hostingContext, config) => that I can access the enviroment, so I can pass it to SeedData.Intialize(services, environment);, but then I can't access the DBcontext. But in the code below, I can access the DBContext, but can't figure out how to access the environment.

To the best of my understanding, I'm injecting the environment in startup.cs, which runs after program.cs. I'm lead to believe that I can't use or Initialize the enviroment in the actual SeedData either, so I thought I could pass it along.
public static void Main(string[] args)
{
    var host = CreateWebHostBuilder(args).Build();

    using (var scope = host.Services.CreateScope())
    {
        var services = scope.ServiceProvider;
        try
        {<br />
            var context = services.GetRequiredService();
            context.Database.Migrate();
            SeedData.Initialize(services);
        }
        catch (Exception ex)
        {
            var logger = services.GetRequiredService>();
            logger.LogError(ex, "An error occurred seeding the DB.");
        }
    }

    host.Run();
}

On issue 2, I just can't seem to understand how create a class for MapPath. I tried this, the code below, but I'm testing on the Database Seed function so I know it's not injected yet because it's injected in startup.cs, and not program.cs.

So I'm flying around in circles, and not really sure how to approach this.
public class ServerPath 
    {
        private IHostingEnvironment _hostingEnvironment;

        public ServerPath(IHostingEnvironment environment)
        {
            _hostingEnvironment = environment;
        }      

        public string MapPath(string path)
        {
            string filePath = string.Empty;
            try
            {
                filePath = Path.Combine(_hostingEnvironment.WebRootPath, path);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }

            return filePath;
        }    

        public string CombinePath(string path, string fileName)
        {
            string filePath = string.Empty;
            try
            {
                filePath = Path.Combine(_hostingEnvironment.WebRootPath, path + "\" + fileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }            

            return filePath;

        }
    }
}
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerDirectory.GetCurrentDirectory Pin
jkirkerx28-Jun-18 9:11
professionaljkirkerx28-Jun-18 9:11 
AnswerRe: .Net Core 2.1, Get the Environment to seed a database so I can get the path Pin
Richard Deeming28-Jun-18 10:26
mveRichard Deeming28-Jun-18 10:26 
GeneralRe: .Net Core 2.1, Get the Environment to seed a database so I can get the path Pin
jkirkerx28-Jun-18 11:56
professionaljkirkerx28-Jun-18 11:56 
QuestionSenior MVC Full Stack Developer Job Postings with Angular Experience Pin
jkirkerx27-Jun-18 8:42
professionaljkirkerx27-Jun-18 8:42 
AnswerRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
F-ES Sitecore27-Jun-18 23:44
professionalF-ES Sitecore27-Jun-18 23:44 
GeneralRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
jkirkerx28-Jun-18 6:50
professionaljkirkerx28-Jun-18 6:50 
AnswerRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
Richard Deeming28-Jun-18 1:03
mveRichard Deeming28-Jun-18 1:03 
GeneralRe: Senior MVC Full Stack Developer Job Postings with Angular Experience Pin
jkirkerx28-Jun-18 6:55
professionaljkirkerx28-Jun-18 6:55 
Question.net Core 2.1, Startup.cs, IConfiguration vs IHostingEnviroment Pin
jkirkerx27-Jun-18 7:14
professionaljkirkerx27-Jun-18 7:14 
AnswerRe: .net Core 2.1, Startup.cs, IConfiguration vs IHostingEnviroment Pin
Richard Deeming27-Jun-18 7:45
mveRichard Deeming27-Jun-18 7:45 
GeneralRe: .net Core 2.1, Startup.cs, IConfiguration vs IHostingEnviroment [solved] Pin
jkirkerx27-Jun-18 8:08
professionaljkirkerx27-Jun-18 8:08 
QuestionBody Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
jkirkerx27-Jun-18 6:26
professionaljkirkerx27-Jun-18 6:26 
AnswerRe: Body Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
Richard Deeming27-Jun-18 7:13
mveRichard Deeming27-Jun-18 7:13 
GeneralRe: Body Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
jkirkerx27-Jun-18 8:13
professionaljkirkerx27-Jun-18 8:13 
GeneralRe: Body Tag, Razor and AngularJS workaround or better idea for body tag cannot have c# in it. Pin
Richard Deeming27-Jun-18 8:18
mveRichard Deeming27-Jun-18 8:18 
Question.Net Core 2.1, DI and System.Web in a separate 2.1 Project Pin
jkirkerx25-Jun-18 12:14
professionaljkirkerx25-Jun-18 12:14 
AnswerRe: .Net Core 2.1, DI and System.Web in a separate 2.1 Project Pin
F-ES Sitecore26-Jun-18 0:03
professionalF-ES Sitecore26-Jun-18 0:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.