-
Notifications
You must be signed in to change notification settings - Fork 193
IHttpContextAccessor resolved as null #646
Comments
In RC2, Related: aspnet/Razor#768, aspnet/Mvc#3936 I really think it's time there's an announcement for this... See aspnet/Mvc#3936 (comment) // @Eilon |
Following is my startup.cs file code snippet ` public void ConfigureServices(IServiceCollection services)
I'm unable to get Httpcontext in my static class ` public static class TestHelper
public static string UrlFinder(this IHtmlHelper helper, string controlid) ` I already tried the steps said in following link comments
Please help us to find out solution. |
@manikandan05 You can't just create an instance of |
Hi @khellang , I just want to get the urlHelper for my action. I tried out get the value from the below mentioned way.
|
@khellang so the behaviour of the DI in core is to return null when things are not registered rather than throw an error? That seems broken =/ I didn't even check for it not being registered because I assumed if something is not registered it would throw saying it cannot resolve. |
@JakeGinnivan Yes, when calling |
@manikandan05 I'm not sure what you're trying to do. You want to resolve You could do something like public static class TestHelper
{
public static string UrlFinder(this IHtmlHelper helper, string controlid)
{
var httpContext = helper.ViewContext.HttpContext;
// Do something with httpContext...
}
} BTW, it sounds like you want to get the URL for something. You know there's already a utility called |
Sweet, i'm all sorted. will leave this issue open for @manikandan05 |
Gonna close this, @manikandan05's issue doesn't seem to be related. |
Hi @JakeGinnivan, still i'm trying to resolve from my end. i didn't get solution for get the value from IUrlHelper in GetRequiredService<>() |
@manikandan05 I suggest you file a separate issue with a good description of what you're trying to achieve and why it's not working. It doesn't seem related to this... |
Hi @khellang, i have tried your solution also, but i'm cant escape from this UrlHelper. Now i have the face some other problem. Please help to find out the solution. |
I'd prefer not to download and unpack a random zip on my computer. Can you post it as a gist or something? Create a GitHub repo? It would be nice if you could try to explain what you're trying to achieve. Or provide more info on what's wrong. 😄 |
Hi @khellang, I have posted my code snippet (gist) in the following online link. https://gist.github.com/manikandan05/5fa6bc50ae739675834fa75ec5025024 |
@manikandan05 I've basically give you the solution above. Get the |
ok @khellang , After HttpContext, i'm not further using RequestServices.GetRequiredService<>() get the UrlHelper value to call Action(controller,method). This is the issue form my starting point. |
@manikandan05 I still can't remember reading what your original issue is. Are you not getting the |
Hi @khellang, Thanks for your valuable suggestion. Now i got the solution 😄 Thanks... |
I am using IdentityServer3 with dotnet core and am upgrading to RC2 and have hit a snag.
I have a custom user service which I want to resolve out of the aspnet core container. So I get access to the Request services like this:
Not pretty, but I couldn't figure out how else to go from identity servers internal container to the request container without doing this. It calls into my factory fine:
Inside the AddScoped callback,
httpContextAccessor
is null. Any ideas what I have missed? The options are resolved fine.The text was updated successfully, but these errors were encountered: