AutoFac And MVC IControllerActivator Needing Container?
Mar 13, 2011
I'm in an interesting situation; I need to pass the IContainer to the IControllerActivator component that I'm defining, yet the IControllerActivator needs to be registered inside of the container. This is because the IControllerActivator will use the container to build the controllers.
I stored the container as a static reference from within the global.asax file; this way, any dependant object (like my activator) on the container can reference it. Since the activator uses the container, and needs to be registered in an autofac module, is there a way to define that this specific mapping needs a reference to the container, or can I register this after the container is built?
View 1 Replies
Similar Messages:
Apr 20, 2010
I'm trying to resolve the AccountController in my application, but it seems that I have a lifetime scoping issue.
builder.Register(c => new MyDataContext(connectionString)).As<IDatabase>().HttpRequestScoped();
builder.Register(c => new UnitOfWork(c.Resolve<IDatabase>())).As<IUnitOfWork>().HttpRequestScoped();
builder.Register(c => new AccountService(c.Resolve<IDatabase>())).As<IAccountService>().InstancePerLifetimeScope();
builder.Register(c => new AccountController(c.Resolve<IAccountService>())).InstancePerDependency();
I need MyDataContext and UnitOfWork to be scoped at the HttpRequestLevel.When I try to resolve the AccountController, I get the following error:No scope matching the expression 'value(Autofac.Builder.RegistrationBuilder`3+<>c__DisplayClass0[...]).lifetimeScopeTag.Equals(scope.Tag)' is visible from the scope in which the instance was requested.
View 2 Replies
Jul 28, 2010
I'm having trouble injecting services dependencies into my WCF service using Autofac 1.4.5. I've read and followed the Autofac wiki page on WcfIntegration but my debugging shows me that my WCF service is created by the System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance() method and not by the AutofacWebServiceHostFactory. What am I doing wrong?
I've set up my ajax.svc file to look like the one in the example for use with WebHttpBinding:
<%@ ServiceHost Language="C#" Debug="true"
Service="Generic.Frontend.Web.Ajax, Generic.Frontend.Web"
Factory="Autofac.Integration.Wcf.AutofacWebServiceHostFactory,
Autofac.Integration.Wcf" %>
My WCF service class Ajax is defined like this:
namespace Generic.Frontend.Web
{
[ServiceContract]
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Ajax
{
public MapWebService MapWebService { get; set;}.....
The service already works fine but I can't get the Autofac bits (read: creation/injection) to work.
Removing the default constructor unfortunately leads to the following exception:
System.InvalidOperationException: The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.
View 3 Replies
Oct 25, 2010
I've been dynamically asigning master pages using code for a number of years as part of a skinning engine. Today however,I'm needing to do a 'simple' ASP.Net site that just uses the out of the box basics.I'm hitting a hurdle though and can't figure why.
[code]...
Now - I want to add an <asp:placeholder> control inside the child page's <Content1> tags - however,the designer's intellisense doesn't show them. If I delete the MasterPageFile tag from the top of the child's page, then all of a sudden it works.Why can't I add a placeholder inside a child form?
View 2 Replies
Mar 3, 2011
I understand how to use jQuery to make an AJAX call to a WebMethod from a normal page, but I'm running into problems doing it from a UserControl (ASCX). Right now the biggest Issue I'm having is that the JavaScript for getting access to the groupDropDown control is not working. It seems that since this is a UserControl hosted within DotNetNuke, the ususal method of getting the CLientID is not working since it is nested down x number of levels. Here is what I have:
Javascript:
function validateEnrolledDate(src, args) {
var isValid;
[code]....
I'm now just referencing a TextBox:<asp:TextBox ID="dealerId" runat="server" CssClass="theDealer" />
The Text in the Textbox is being set in Server Side code, and it is visible on screen.The alert message is "undefined", so something is still happening so that it is not getting the value of that textbox...
View 1 Replies
Jan 5, 2011
2nd in an occasional series:
Here's the first one
Is CAT.NET correct that the following is a genuine vulnerability in ASP.NET or is it a false positive?
var myInt = Int32.Parse(txtUserInput.Text);
Response.Redirect(string.Format("myPage.aspx?myId={0}", myInt);
CAT.NET is reporting this as a redirect vulnerability needing remediation via encoding myInt.
View 3 Replies
May 27, 2010
I've been developing an ASP.NET site on an older machine running XP home. I recently got a new Win 7 PC and moved all my project files across. When I try and run the project, I get this error message: "Failed to decrypt using provider 'MyRsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened." I realised that I encrypted parts of my web.config file using a RSA encryption. This is where the problem now lies. I'm not sure how to get that key working again so that I can use it on my new machine. I exported the key from the older machine and imported it using:
aspnet_regiis -pi "RSAProviderName" "C:RSA_configkey.xml"
This was imported successfully. I then ran the project, but the same error message came up. I figured it might be a permission thing, so I ran:
aspnet_regiis -pa "RSAProviderName" "Desktop" -full
This was also successful, but I still get the error. From reading around, I've seen people use "ASPNET" instead of "Desktop" (Desktop is my machine name). However, when I try and use "ASPNET", I get: No mapping between account name and security IDs was done. <Exception from HRESULT = 0x80070534 I can't work on the project until this is fixed,
View 1 Replies
Jan 18, 2010
In a section in the <head> tags of my document I have code that lets me use the Id of my asp.net control from JavaScript like this:
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
However, if I want to modify the page structure in later stages of the page life cycle, it give me an error because I have the ASP tags in there. A work-around is enclosing the ASP tags in a server control like this:
<div id="customerIdContainer" runat="server">
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
</div>
But then I get a warning that a div tag is not allowed in the head tag. So is there a container tag that is valid in the head that I can add runat="server" to to make it a server control so I can workaround this problem without the warnings?
View 2 Replies
Jan 25, 2012
I have a tabcontainer with 5 tab panels in it. The second tab has two listitems, which require an autopostback, but this then defaults back to the first tab, is there a way it can stay on the same tab?
View 7 Replies
Aug 4, 2010
I have a tab container on a web page, in which several panels are loaded with heavy peice of data, what i do, i only load the defualt tab data on page load, and the rest of data(i.e data in other tabs) loads behind the screen(i.e using asynchronous request), just to speed up page rendering. now when the page completely rendered(with only default tab data) the load event of javascript fires and it start populating data into other tabs, in this situation when i click any other tab immediately after rendering, it shows the half rendered panel(i.e the data is rendering in panel or the back process is running), which looks awkward sometimes.
So i need to stop the click of any tab until the data into that panel(or in all the panels) fully rendered, by displaying a wait or progress bar image, and then opens up that panel. i need whenever user click on a tab, a wait image should display on the tab header until the panel fully rendered, and then panel will opens up, none of the panel displays half or no data.
View 9 Replies
Aug 6, 2010
I usually use expressions like this
CommandArgument='<%# Container.DataItemIndex.ToString() %> '
But I could not find Container in the msdn,
View 2 Replies
May 24, 2010
Is there a way to make helper in Asp.Net MVC to wrap other html like this:
<div class="lightGreyBar_left">
<div class="lightGreyBar_right">
<!--Content--> [code]...
So that helper will render containing divs and content that is passed to helper method as parameter.
View 1 Replies
Jul 14, 2010
//Controller code
CookieContainer cookieContainer = new CookieContainer();
//makes new cookie here
cookieContainer.Add(myCookie);
//Service/Facade code
//myCookie gets passed here
How do I pull the cookie out of the container to make sure it's the right cookie?
View 1 Replies
Jun 24, 2010
I'm running into a weird issue.. Basically, a user logs into a page and based on his role status(admin or user) determines how many tabs he sees in a tabcontainer. If he is just a "user" then tab index 0 and 1 need to be hidden because they contain admin only functionality.
if(user)
{
Container.Tabs[0].visible = false;
Container.Tabs[1].visible = false;
}
However the problem is if I set more than 1 tab index to visible = false the entire container disappears. Could this be a bug? I know you can only have one tab visible at a time.
View 2 Replies
Apr 19, 2010
My web.comfig file in the webserver is encrypted . I want to do a change to the config file. While I'm trying to decrypt from the command prompt on the server using following command. "aspnet_regiis -pd "appSettings" -app "/AppName" I endup with the following error message. Failed to decrypt using provider 'CustomProvider'. Error message from the provider: The RSA key container could not be opened. The RSA key container could not be opened. Failed! The same command has been working in other environments except in my servers. Also I'm using web forms and I tried the same in both the servers. I have gone through all websites but no use.
View 6 Replies
May 7, 2010
I am trying to debug on my local machine an application that has encrypted connection strings. The error when I go to register the Key Container is:
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727>aspnet_regiis -pa "CompanyDirector
yKeyContainer" "PHXDEVELOPER26ASPNET"
Adding ACL for access to the RSA Key container. The RSA key container was not found. Failed! I am getting this when I run the debug:
Server Error in '/' Application.
Configuration Error
Description:
An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Failed to decrypt using provider 'CompanyDirectoryRsaProvider'. Error message from the provider: The RSA key container could not be opened.
Source Error:
[Code]....
Source File: C:ProjectsSystemInformationSystemInformationweb.config Line:
21
Version Information: Microsoft .NET Framework Version:2.0.50727.3607; ASP.NET Version:2.0.50727.3082
And, last but not least, I did copy all the MachineKeys over into my MachineKey directory as well, with one explicitly saying CompanyDirectoryKeyProvider in it. What I am doing wrong and what do I need to do to correct this?
View 2 Replies
Aug 25, 2010
1) I want to create a rsa key in c# and export the container. I am having difficulty. I create container like this:
[Code]....
The msdn example says I can export the container with this syntax: aspnet_regiis -pa "XML_ENC_RSA_KEY" "NT AUTHORITYNETWORK SERVICE". This does not work on my XP Host PC. I belive this is applicable for Windows 2003 Server. So what is the correct syntax for exporting rsa key container from XP host?
2) To get aspnet_regiis.exe path I did something like this:
[Code]....
But this path may be different for each host, based on the .NET verison installation. Is there a way to get the aspnet_regiis.exe path from registry or a environment varaible?
3) Once I get the path to aspnet_regiis.exe I want to invokve it from c# like this.Is this code correct?
[Code]....
View 1 Replies
Feb 17, 2011
Does any one know the cmd line call to retrieve the existing RSA key container name so that I can export these RSA keys to another machine?
View 2 Replies
May 11, 2010
I have two administrator users on my machine. With the first one I am creating a machine level key:
spnet_regiis -pc "NetFrameworkConfigurationKey" -exp
and I see it created in "C:Documents and SettingsAll UsersApplication DataMicrosoftCryptoRSAMachineKeys".
Now I am trying to add access privileges with the second one:
"c:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis.exe" -pa NetFrameworkConfigurationKey "XXX" Adding ACL for access to the RSA Key container... The RSA key container was not found. Failed!
View 12 Replies
Feb 22, 2010
I'm new to ASP.NET, and I'm self-taught. I suspect that's the cause of my problem, but here goes. I'm using .NET 3.5 and have installed the toolkit. I want to add a Tab Container to an AJAX Webform. When I drag the control from the toolbox to the Webform, nothing happens. I saw that someone was having this problem with extenders, but I don't believe the Tab Container is an extender. If I'm wrong, let me know, but shouldn't I be able to place the tab container directly on the webform?
View 5 Replies
Mar 1, 2011
After about 30 Minutes the whole Unity Container is away, that means that all my Dependencies rises null exceptions, because they can't get resolved.
Global.asax:
[Code]....
[Code]....
View 3 Replies
Feb 25, 2010
I created a aspx page that uses a master page. Inside I have a control, let's say txtName and I have a submit button, that when I press it it will submit the text in the txtName to another page.The problem is that the Request.Form key does not have the txtName, instead it something like clt00$Container0&txtName.Isn't there a way to easily find the key that I want to retrieve from there?
View 2 Replies
Jan 19, 2011
At MVC 2 I do this: [URL]
But with MVC 3, I canīt create a child container per request(in really I can, using the old way), because container is hold at a static variable: DependencyResolver.SetResolver(new UnityDependencyResolver(container));
Which the better way to Dispose created objects? Since I use Repositories and Entity Framework (that need Dispose). As said here [URL] HttpRequestLifetimeManager donīt dispose objects....
View 1 Replies
Mar 8, 2011
I am doing a project in ASP.NET MVC in which I want to implement an IoC container. I am new to IoC containers and have been searching to find a solution to my problem, but so far to no avail.
The problem is dat data is distributed across various databases. Once a user is logged in, the database for the user is retrieved from an authorization database and then set in the user session. That user session is passed on to the services and repositories when they are constructed, so they can use it when they need it to access the database.
A typical bare stripped service (without interfaces and ioc) looks like this:
private CompetitionRepository _CompetitionRepo;
public CompetitionService(DataContext dataContext)
: this (new CompetitionRepository(dataContext))
{ }
[code]...
The "DataContext" contains a couple of properties with which the correct database is selected for the session. Because the Services and Repositories don't have access to the session itself (which is outside of their scope) they need this object.
View 1 Replies
Nov 19, 2010
I cannot figure out how to get my simple container control to properly display in the designer. Here is the basic markup of the custom control:
<div>
<div>Title</div>
<div>
<!-- ASP.Net child controls -->
</div>
</div>
Here is how it looks at runtime (title and then the child control is a GridView):
Here is the simple code for the basic container control:
namespace Shoe.Controls
//[Designer(typeof(ApplicationWindowDesigner))]
//[ParseChildren(false)]
//[PersistChildren(true)]
[ToolboxData("<{0}:ApplicationWindow runat="server"></{0}:ApplicationWindow>")]
public class ApplicationWindow : System.Web.UI.WebControls.Panel
{
#region Designer Properties
[Category("Appearance")]
[DefaultValue("Application")]
[Description("Title that will appear at the top of the Window.")]
[Browsable(true)]
public string Title
get{return (ViewState["ApplicationWindowTitle"] == null)?
string.Empty :
(string)ViewState["ApplicationWindowTitle"];}
set{ViewState["ApplicationWindowTitle"] = value;}
[code...]
As you see the code above, it is currently based off of the Panel control. However, I have also tried just using WebControl as the base class and then providing my own designer as follows:
namespace Shoe.Controls
public class ApplicationWindowDesigner : ContainerControlDesigner
//public class ApplicationWindowDesigner : ControlDesigner
public override void Initialize(IComponent component)
base.Initialize(component);
SetViewFlags(ViewFlags.DesignTimeHtmlRequiresLoadComplete, true);
[code...]
This is also what it looks like when I use WebControl as the base class for the control and use a designer based off of ContainerControlDesigner (child controld, but my title bar and divs are missing).What am I missing? I've found several examples of ContainerControlDesigner but none of them really add anything to the surrounding control like I am.
View 1 Replies